Last active
September 6, 2021 03:11
-
-
Save nickytoh/fc0eb01271a45448db16 to your computer and use it in GitHub Desktop.
Revisions
-
Nicky Toh renamed this gist
Jun 11, 2014 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
Nicky Toh created this gist
Jun 11, 2014 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,114 @@ var uuid = require('node-uuid'), https = require('https'); function iCloud(appleId, password) { this.urls = { "version" : "https://www.icloud.com/system/version.json", "validate": "/setup/ws/1/validate?clientBuildNumber={0}&clientId={1}", "login": "/setup/ws/1/login?clientBuildNumber={0}&clientId={1}" } this.appleId = appleId; this.password = password; this.clientBuildNumber = '1P24'; this.clientId = uuid.v1().toString().toUpperCase(); // console.log('Generated UUID: ' + this.clientId); this.cookie = null; this.instance = null; this.validate(); } iCloud.prototype = { validate: function() { var me = this; var endpoint = this.urls.login .replace('{0}', this.clientBuildNumber) .replace('{1}', this.clientId); // console.log(endpoint); var options = { host: "p12-setup.icloud.com", path: endpoint, method: 'POST', headers: { 'Origin': 'https://www.icloud.com', 'Referer': 'https://www.icloud.com', 'User-Agent': 'Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.114 Safari/537.36' } }; var data = JSON.stringify({ apple_id: this.appleId, password: this.password, extended_login: false }); var request = https.request(options, function(res) { if (res.headers['set-cookie']) me.cookie = res.headers['set-cookie']; var buffer = ''; res.on('data', function(data) { buffer += data; }); res.on('end', function() { me.instance = JSON.parse(buffer); var dsid = me.instance.dsInfo.dsid; var getContactListUrl = '/co/startup?clientBuildNumber={1}&clientId={2}&clientVersion=2.1&dsid={3}&locale=zh_TW&order=last%2Cfirst' .replace('{1}', me.clientBuildNumber) .replace('{2}', me.clientId) .replace('{3}', dsid); // &id={4} var options2 = { host: me.instance.webservices.contacts.url.replace('https://', '').replace(':443', ''), path: getContactListUrl, method: 'GET', headers: { 'Origin': 'https://www.icloud.com', 'Referer': 'https://www.icloud.com', 'Cookie': me.cookie.join('; '), 'User-Agent': 'Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.114 Safari/537.36' } }; var req2 = https.request(options2, function(res) { var buf2 = ''; res.on('data', function(data) { buf2 += data; }); res.on('end', function() { var contacts = JSON.parse(buf2).contacts; for (var i = 0; i < contacts.length; i ++ ) { console.log(contacts[i].lastName + ' ' + contacts[i].firstName + ', email(' + contacts[i].emailAddresses[0].label + '): ' + contacts[i].emailAddresses[0].field ); } }); }); req2.end(); }); }); request.write(data); request.end(); } }; new iCloud('[email protected]', '12345678');