# (c) "Neil Young" (neil.young@freenet.de) # # This script is published under GPL (included below) # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . # from struct import * import httplib, location from location import * # Tailor this! #mcc, mnc, lac, cid = 0,0,0,0 def req((mcc, mnc, lac, cid), attempt_short_cid): if cid > 65536: network = 5 else: network = 3 if attempt_short_cid: cid &= 65536 return pack('>BBBBBBBBBBBBBBBBBLLLHLLLLLL', 0,14,0,0,0,0,0,0,0,0,0,0,0,0,0,0,27,mnc, mcc, network, 0, cid, lac, mnc, mcc, 0, 0) def GLoc(): try: headers = {"Content-type": "application/binary", "Connection": "close"} conn = httplib.HTTPConnection("www.google.com") body = req(gsm_location(), False) conn.request("POST", "/glm/mmap", body, headers) resp = conn.getresponse() answer = resp.read() conn.close() if resp.status == 200: #result, = unpack('>L', answer[3:7]) a, b, result, lat, lon, c, d, e = unpack(">hBiiiiih", answer) if result == 0: print "OK", result, lat/1000000.0, lon/1000000.0 return (lat/1000000.0, lon/1000000.0) else: print "ERROR", result return (0,0) else: print "HTTP Error "+ str(resp.status) return (0,0) print "Bytes sent/received: about "+str(len(body)+len(answer)+400) # 400: estimated header length except: print "Error"