Last active
April 29, 2020 20:43
-
-
Save phenotypic/d5916de9a5eeb5faa6073ece0e0068be to your computer and use it in GitHub Desktop.
Python Wi-Fi scanner for macOS
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
import subprocess | |
import re | |
from prettytable import PrettyTable | |
airport = '/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport' | |
print('Scanning for networks...\n') | |
scan = subprocess.run(['sudo', airport, '-s'], stdout=subprocess.PIPE) | |
scan = scan.stdout.decode('utf-8') | |
scan = scan.split('\n') | |
count = len(scan) - 1 | |
scan = [o.split() for o in scan] | |
list = PrettyTable(['Number', 'Name', 'BSSID', 'RSSI', 'Channel', 'Security']) | |
networks = {} | |
for i in range(1, count): | |
bssid = re.search('(?:[0-9a-fA-F]:?){12}', ' '.join(scan[i])).group(0) | |
bindex = scan[i].index(bssid) | |
network = {} | |
network['ssid'] = ' '.join(scan[i][0:bindex]) | |
network['bssid'] = bssid | |
network['rssi'] = scan[i][bindex + 1] | |
network['channel'] = scan[i][bindex + 2].split(',')[0] | |
network['security'] = scan[i][bindex + 5].split('(')[0] | |
networks[i] = network | |
list.add_row([i, network['ssid'], network['bssid'], network['rssi'], network['channel'], network['security']]) | |
print(list) | |
x = int(input('\nSelect a network: ')) | |
print(networks[x]['bssid'], networks[x]['ssid'], networks[x]['channel']) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment