Skip to content

Instantly share code, notes, and snippets.

@keithweaver
Last active March 20, 2023 18:01
Show Gist options
  • Save keithweaver/00edf356e8194b89ed8d3b7bbead000c to your computer and use it in GitHub Desktop.
Save keithweaver/00edf356e8194b89ed8d3b7bbead000c to your computer and use it in GitHub Desktop.
Get Wifi information on Mac OSx using Python
# 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
@Alexandro1112
Copy link

Alexandro1112 commented Jan 24, 2023

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