Skip to content

Instantly share code, notes, and snippets.

@tominsam
Created November 24, 2010 15:54
Show Gist options
  • Save tominsam/713859 to your computer and use it in GitHub Desktop.
Save tominsam/713859 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'net/https'
require 'json'
class PhoneFinder
attr_accessor :proxyhost, :proxyport
attr_accessor :username, :password
def initialize(u, p)
if ENV["http_proxy"]
proxy = URI.parse(ENV["http_proxy"])
self.proxyhost = proxy.host
self.proxyport = proxy.port
end
self.username = u
self.password = p
end
def call(url, data = {})
puts "calling #{url}"
uri = URI.parse(url)
# if proxy is nil, proxy is just a passthrough
puts uri.host
http = Net::HTTP::Proxy(self.proxyhost, self.proxyport).new(uri.host, uri.port)
http.use_ssl = true
req = Net::HTTP::Post.new( uri.path )
headers = {
'X-Apple-Find-Api-Ver' => '2.0',
'X-Apple-Authscheme' => 'UserIdGuest',
'X-Apple-Realm-Support' => '1.0',
'X-Client-Name' => "Steve's iPhone",
'X-Client-Uuid' => '0cf3dc491ff812adb0b202baed4f94873b210853',
'Accept-Language' => 'en-us',
'Pragma' => 'no-cache',
'Connection' => 'keep-alive',
"User-Agent" => "Find iPhone/1.1 MeKit (iPhone: iPhone OS/4.2.1)",
}
clientContext = {
"appName" => "FindMyiPhone",
"appVersion" => "1.1",
"buildVersion" => "99",
"deviceUDID" => "0cf3dc491ff812adb0b202baed4f94873b210853",
"inactiveTime" => 2147483647,
"osVersion" => "4.2.1",
"personID" => 0,
"productType" => "iPhone3,1",
}
req.content_type = "application/json; charset=utf-8"
req.body = { :clientContext => clientContext }.merge(data).to_json
puts "POSTING to #{uri.path}: #{ req.body }"
for h,v in headers
req[h] = v
end
req.basic_auth self.username, self.password
response, data = http.request(req)
return data.split(/[\r\n]+/).map{|l| JSON.parse(l) }
end
def find
un = URI.escape(username, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]"))
self.call("https://fmipmobile.me.com/fmipservice/device/#{un}/initClient")
end
end
finder = PhoneFinder.new("user", "password")
p finder.find
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment