import sys
print(sys.platform)
import subprocess
subprocess.check_output(["/System/Library/PrivateFrameworks/Apple80211.framework/Resources/airport", "-s"])
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()
getWifiMacAddresses()
googleMapsAPIkey=''
#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)
url='https://www.googleapis.com/geolocation/v1/geolocate?key={}'.format(googleMapsAPIkey)
import requests
r = requests.post(url, json=postjson)
r.json()
gl=[]
for h in hotspots:
addr,db=hotspots[h]
gl.append(requests.post(url, json={'macAddress':addr, 'signalStrength':int(db)}))
for g in gl:
print(g.json())
!pip install -U googlemaps
! apt-get -y install wireless-tools
!iwlist scanning
#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)
'''