Open kootenpv opened 8 years ago
Because I don't have any OSX environment to develop, now pywifi doesn't support OSX yet.
So, I only need to scan wifi. I provide code below. I don't really understand why there's so much interface for windows and linux, but would it be possible for you to create a skeleton around this so we can add OSX support? I could then benefit from using pywifi, and anyone after me :)
import subprocess
import os
def get_parser(line):
bbsid = line.index("BSSID")
rssi = line.index("RSSI")
channel = line.index("CHANNEL")
security = line.index("SECURITY")
return [("SSID", (0, bbsid)),
("BSSID", (bbsid, rssi)),
("RSSI", (rssi, channel)),
("SECURITY", (security, -1))]
def sample():
cmd = "/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport -s"
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True)
(out, _) = proc.communicate()
dc = {}
parser = []
for line in out.decode("utf8").split("\n"):
if line.strip().startswith("SSID"):
parser = get_parser(line)
elif line:
row = [line[inds[0]:inds[1]].strip() for name, inds in parser]
# row[0] is SSID
# row[1] is BSSID
# row[2] is RSSI/Signal
key = row[0] + " " + row[1]
value = int(row[2])
dc[key] = value
return dc
Output:
{
'H368NDF1690 54:22:f8:XXXXX': -69,
'KPN Fon XX:22:XX:XX:16:91': -70
}
Now pywifi is still under prototype stage, so I need more time to refactor its structure for maintainability. I will add osx folder under pywifi folder you can implement following:
in osx_wifiutil.py file
in wifiutils.py file I already filled the code based on above osx_wifiutil.py utilities. If no big issue, I think you don't need to modify it.