-
-
Save sir4ju1/4d837f9ea708024d30c7 to your computer and use it in GitHub Desktop.
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 characters
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'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment