Last active
March 20, 2023 18:01
-
-
Save keithweaver/00edf356e8194b89ed8d3b7bbead000c to your computer and use it in GitHub Desktop.
Get Wifi information on Mac OSx using Python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# I tried to use the pip install wifi but it really didn't work. | |
# So created this | |
import subprocess | |
process = subprocess.Popen(['/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport','-I'], stdout=subprocess.PIPE) | |
out, err = process.communicate() | |
process.wait() | |
print(out) | |
''' | |
Print out is: | |
agrCtlRSSI: -50 | |
agrExtRSSI: 0 | |
agrCtlNoise: -91 | |
agrExtNoise: 0 | |
state: running | |
op mode: station | |
lastTxRate: 243 | |
maxRate: 300 | |
lastAssocStatus: 0 | |
802.11 auth: open | |
link auth: wpa2 | |
BSSID: 24:de:c6:a6:9c:da | |
SSID: QueensuSecure_WPA2 | |
MCS: 14 | |
channel: 44,1 | |
''' | |
# SSID is the wifi name |
Good! useful
Maybe make this:(if need get available wifi networks)
import subprocess
def get_list_wifi_networks():
""" Function output all wi-fi networks,
which available for your devise."""
scan_cmd = subprocess.Popen(['airport', '-s'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
scan_out, scan_err = scan_cmd.communicate()
scan_out_data = dict()
scan_out_lines = str(scan_out).split("\\n")[1:-1]
for each_line in scan_out_lines:
split_line = [e for e in each_line.split(" ") if e != ""]
line_data = {"SSID": split_line[0], "RSSI": int(split_line[2]), "channel": split_line[3],
"HT": (split_line[4] == "Y"), "CC": split_line[5], "security": split_line[6]}
scan_out_data[split_line[1]] = line_data
return scan_out_data
for names in get_list_wifi_networks().values():
i = list(names.values())[0]
print(i.split())
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
to expand on this, here's a function that will return all the output of the
airport
stdout into a python dictionary, allowing you easily extract the values independently:"""prints only the exact SSID string"""