#!/usr/bin/env python # coding: utf-8 # In[ ]: import sys print(sys.platform) # In[ ]: import subprocess subprocess.check_output(["/System/Library/PrivateFrameworks/Apple80211.framework/Resources/airport", "-s"]) # In[ ]: import sys print(sys.platform) #/System/Library/PrivateFrameworks/Apple80211.framework/Resources/airport import subprocess def getWifiMacAddresses(): #autodetect platform and then report based on this? results = subprocess.check_output(["/System/Library/PrivateFrameworks/Apple80211.framework/Resources/airport", "-s"]) #win? #results = subprocess.check_output(["netsh", "wlan", "show", "network"]) #linux? #! apt-get -y install wireless-tools #results = subprocess.check_output(["iwlist","scanning"]) results = results.decode("utf-8") # needed in python 3 ls = results.split("\n") ls = ls[1:] macAddr={} for l in [x.strip() for x in ls if x.strip()!='']: ll=l.split(' ') macAddr[l.strip().split(' ')[0]]=(l.strip().split(' ')[1], l.strip().split(' ')[2]) return macAddr #For Mac: postjson={'wifiAccessPoints':[]} hotspots=getWifiMacAddresses() for h in hotspots: addr,db=hotspots[h] postjson['wifiAccessPoints'].append({'macAddress':addr, 'signalStrength':int(db)}) url='https://www.googleapis.com/geolocation/v1/geolocate?key={}'.format(googleMapsAPIkey) import requests r = requests.post(url, json=postjson) r.json() # In[ ]: getWifiMacAddresses() # In[ ]: googleMapsAPIkey='' # In[ ]: #import json postjson={'wifiAccessPoints':[]} hotspots=getWifiMacAddresses() for h in hotspots: addr,db=hotspots[h] postjson['wifiAccessPoints'].append({'macAddress':addr, 'signalStrength':int(db)}) #json.dumps(postjson) # In[ ]: url='https://www.googleapis.com/geolocation/v1/geolocate?key={}'.format(googleMapsAPIkey) # In[ ]: import requests r = requests.post(url, json=postjson) # In[ ]: r.json() # In[ ]: gl=[] for h in hotspots: addr,db=hotspots[h] gl.append(requests.post(url, json={'macAddress':addr, 'signalStrength':int(db)})) # In[ ]: for g in gl: print(g.json()) # In[ ]: get_ipython().system('pip install -U googlemaps') # In[ ]: get_ipython().system(' apt-get -y install wireless-tools') # In[ ]: get_ipython().system('iwlist scanning') # In[ ]: #http://stackoverflow.com/a/31868561/454773 #win ''' import subprocess results = subprocess.check_output(["netsh", "wlan", "show", "network"]) #Adding: / mode=bssid / gives SSIDS?#or maybe: netsh wlan show allresults = results.decode("ascii") # needed in python 3 results = results.replace("\r","") ls = results.split("\n") ls = ls[4:] ssids = [] x = 0 while x < len(ls): if x % 5 == 0: ssids.append(ls[x]) x += 1 print(ssids) '''