利用Python读取笔记本曾经连接过的所有无线AP信息并利用Wigle进行物理定位
1 import requests 2 import subprocess 3 import sys 4 import re 5 6 7 class APInfo: #此处AP表示无线热点 8 def __init__(self) -> None: 9 self.wigle_API_url = 'https://api.wigle.net/api/v2/network/search' 10 self.wigle_API_name = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' #需要在wigle注册账户,并获得该API name 11 self.wigle_API_token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' #需要在wigle注册账户,并获得该API token 12 13 def get_AP_BSSID_list(self): 14 try: 15 result = subprocess.check_output('netsh wlan show networks mode=bssid', shell=True, stderr=subprocess.STDOUT,encoding='gbk') 16 pattern = r'(?:BSSID\s*1\s*:\s*)(.*)' 17 BSSID_list = re.findall(pattern,result) #获得本机上所有无线AP的BSSID,也就是MAC地址列表 18 return BSSID_list 19 except Exception as e: 20 print(e) 21 22 23 def geo_ap(self, bssid): 24 headers = { 25 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:100.0) Gecko/20100101 Firefox/100.0' 26 } 27 try: 28 response = requests.get(url=self.wigle_API_url,headers=headers,auth=(self.wigle_API_name,self.wigle_API_token), params={'bssid':bssid}).json() #需要将API name以及API token以auth基础认证的方式提交 29 print(response) 30 except Exception as e: 31 print(e) 32 sys.exit(0) 33 34 def run(self): 35 bssid_list = self.get_AP_BSSID_list() 36 for bssid in bssid_list: 37 self.geo_ap(bssid) 38 39 40 41 if __name__ == '__main__': 42 ap = APInfo() 43 ap.run()
STRIVE FOR PROGRESS,NOT FOR PERFECTION