├── package.json ├── README.md ├── examples └── device-info.js └── lib └── iphone-finder.js /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "iphone-finder", 3 | "description": "Simple library to locate iOS devices (iPhone, iPod and iPad)", 4 | "version": "1.0.1", 5 | "homepage": "http://github.com/ThomasHenley/node-iphone-finder.git", 6 | "author": { 7 | "name": "Thomas Henley", 8 | "email": "thomas@hendore.co.uk", 9 | "url": "http://hendore.co.uk" 10 | }, 11 | "repository": { 12 | "type": "git", 13 | "url": "http://github.com/ThomasHenley/node-iphone-finder.git" 14 | }, 15 | "main": "./lib/iphone-finder", 16 | "keywords": ["iphone", "ipod", "ipad", "find", "locate"], 17 | "license" : "MIT" 18 | } 19 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # iphone-finder 2 | 3 | Simple library to locate iOS devices (iPhone, iPod and iPad) 4 | 5 | ## Installation 6 | 7 | First install [node.js](http://nodejs.org/). Then: 8 | 9 | $ npm install iphone-finder 10 | 11 | ## Usage 12 | 13 | var iPhoneFinder = require('iphone-finder'); 14 | 15 | // Replace with valid iCloud email and password 16 | var iCloudUser = 'my@icloud.com'; 17 | var iCloudPass = '#############'; 18 | 19 | // Find all devices the user owns 20 | iPhoneFinder.findAllDevices(iCloudUser, iCloudPass, function(err, devices) { 21 | // Got here? Great! Lets see some device information 22 | devices.forEach(function(device) { 23 | // Output device information 24 | console.log('Device Name: ' + device.name); 25 | console.log('Device Type: ' + device.modelDisplayName); 26 | 27 | // Output location (latitude and longitude) 28 | var lat = device.location.latitude; 29 | var lon = device.location.longitude; 30 | console.log('Lat/Long: ' + lat + ' / ' + lon); 31 | 32 | // Output a url that shows the device location on google maps 33 | console.log('View on Map: http://maps.google.com/maps?z=15&t=m&q=loc:' + lat + '+' + lon); 34 | }); 35 | }); 36 | -------------------------------------------------------------------------------- /examples/device-info.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Simple example, get all devices owned by user 3 | * and output some device information and location 4 | * 5 | * Author: Thomas Henley 6 | */ 7 | var iPhoneFinder = require('iphone-finder'); 8 | 9 | // Replace with valid iCloud email and password 10 | var iCloudUser = 'my@icloud.com'; 11 | var iCloudPass = '#############'; 12 | 13 | // Find all devices the user owns 14 | iPhoneFinder.findAllDevices(iCloudUser, iCloudPass, function(err, devices) { 15 | // Got here? Great! Lets see some device information 16 | devices.forEach(outputDevice); 17 | }); 18 | 19 | // Output device type, name and location. Includes link to google maps with long/lat set 20 | function outputDevice(device) { 21 | // Output device information 22 | console.log('Device Name: ' + device.name); 23 | console.log('Device Type: ' + device.modelDisplayName); 24 | 25 | // Output location (latitude and longitude) 26 | if (device.location) { 27 | if (device.location.latitude && device.location.longitude) { 28 | var lat = device.location.latitude; 29 | var lon = device.location.longitude; 30 | console.log('Lat/Long: ' + lat + ' / ' + lon); 31 | 32 | // Output a url that shows the device location on google maps 33 | console.log('View on Map: http://maps.google.com/maps?z=15&t=m&q=loc:' + lat + '+' + lon); 34 | } 35 | } else { 36 | console.log('Device Location: unknown'); 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /lib/iphone-finder.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Simple library to locate iOS devices (iPhone, iPod and iPad) 3 | * 4 | * Author: Thomas Henley 5 | */ 6 | var Buffer = require('buffer').Buffer; 7 | var https = require('https'); 8 | 9 | module.exports.findAllDevices = function(username, password, callback) { 10 | // Send a request to the find my iphone service for the partition host to use 11 | getPartitionHost(username, password, function(err, partitionHost) { 12 | // Now get the devices owned by the user 13 | getDeviceDetails(partitionHost, username, password, callback); 14 | }); 15 | }; 16 | 17 | function getPartitionHost(username, password, callback) { 18 | postRequest('fmipmobile.icloud.com', username, password, function(err, response) { 19 | // Return the partition host if available 20 | return callback(null, response.headers['x-apple-mme-host']); 21 | }); 22 | }; 23 | 24 | function getDeviceDetails(partitionHost, username, password, callback) { 25 | postRequest(partitionHost, username, password, function(err, response) { 26 | var allDevices = JSON.parse(response.body).content; 27 | return callback(null, allDevices); 28 | }); 29 | } 30 | 31 | function postRequest(host, username, password, callback) { 32 | var apiRequest = https.request({ 33 | host: host, 34 | path: '/fmipservice/device/' + username + '/initClient', 35 | headers: { 36 | Authorization: 'Basic ' + new Buffer(username + ':' + password).toString('base64') 37 | }, 38 | method: 'POST' 39 | }, function(response) { 40 | var result = {headers: response.headers, body: ''}; 41 | response.on('data', function(chunk) {result.body = result.body + chunk; }); 42 | response.on('end', function() { return callback(null, result); }); 43 | }); 44 | apiRequest.end(); 45 | }; 46 | --------------------------------------------------------------------------------