Skip to content

Instantly share code, notes, and snippets.

@0x6d61
Created June 24, 2018 07:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 0x6d61/91671f1094ba99e5034b3ee84ff8229a to your computer and use it in GitHub Desktop.
Save 0x6d61/91671f1094ba99e5034b3ee84ff8229a to your computer and use it in GitHub Desktop.
Get Physical Location Script
import subprocess
import re
import requests
import time
def wifi():
while True:
bssids = []
signal = []
try:
result = subprocess.check_output("netsh wlan show network mode=bssid",stderr=subprocess.STDOUT,shell=True)
for i in result.decode('cp932').split("\r\n"):
BSSID = re.search(r"[0-9a-f]{2}:[0-9a-f]{2}:[0-9a-f]{2}:[0-9a-f]{2}:[0-9a-f]{2}:[0-9a-f]{2}",i)
if BSSID:
bssids.append(BSSID.group())
SIGNAL = re.search(r"[0-9]{2,3}%",i)
if SIGNAL:
signal.append(SIGNAL.group().strip("%"))
highBSSID = ','.join([i for i,j in zip(bssids,signal) if int(j) >= 70])
requests.get("http://192.168.11.7/wifi?"+highBSSID)
time.sleep(300)
except Exception as e:
pass
wifi()
from http.server import HTTPServer, SimpleHTTPRequestHandler
import re
import json
import requests
import datetime
def api_request(wifi):
API_KEY=""
url = "https://www.googleapis.com/geolocation/v1/geolocate?key={0}".format(API_KEY)
macaddr = [dict(macAddress=i) for i in wifi.split(",")]
google_api_json = {
'homeMobileCountryCode': 310,
'homeMobileNetworkCode': 410,
'radioType': 'lte',
'considerIp': 'false',
'carrier': 'Vodafone',
'wifiAccessPoints':macaddr
}
jpost = json.dumps(google_api_json)
req = requests.post(url,data=jpost,headers={'content-type': 'application/json'})
location = json.loads(req.text)
realaddress= "http://maps.google.com/maps/api/geocode/json?latlng={0},{1}&sensor=false&language=ja".format(location["location"]["lat"],location["location"]["lng"])
realreq = requests.get(realaddress)
GMAPs = json.loads(realreq.text)
time = "{0:%Y-%m-%d %H:%M:%S}".format(datetime.datetime.now())
print("[{0}] {1}".format(time,GMAPs['results'][0]['formatted_address']))
class MyHandler(SimpleHTTPRequestHandler):
def log_message(self,fomat,*args):
pass
def do_GET(self):
body = b'Hello World'
wifi = re.search(r"[0-9a-f]{2}:.*",self.path)
if wifi:
api_request(wifi.group())
self.send_response(200)
self.send_header('Content-type', 'text/html; charset=utf-8')
self.send_header('Content-length', len(body))
self.end_headers()
self.wfile.write(body)
host = '0.0.0.0'
port = 80
httpd = HTTPServer((host, port), MyHandler)
print('serving at port', port)
httpd.serve_forever()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment