1
mirror of git://git.acid.vegas/random.git synced 2024-11-14 12:06:38 +00:00
random/networking/ap.py
2019-06-27 22:39:56 -04:00

23 lines
1.2 KiB
Python

#!/usr/bin/env python
import re, subprocess
interface = 'wlp1s0'
def between(source, start, stop):
data = re.compile(start + '(.*?)' + stop, re.IGNORECASE|re.MULTILINE).search(source)
if data : return data.group(1)
else : return False
output = subprocess.check_output(f'sudo iwlist {interface} scanning | egrep \'Cell |Channel|Frequency|Encryption|Quality|ESSID|Mode\'', shell=True).decode()
access_points = output.split(' Cell ')[1:]
print('\033[30m\033[47mMAC Address Channel Frequency Quality Signal Mode Encryption ESSID\033[0m')
for ap in access_points:
address = between(ap, 'Address: ', '\n')
channel = between(ap, 'Channel:', '\n').ljust(7)
frequency = between(ap, 'Frequency:', ' GHz')[:3]
quality = between(ap, 'Quality=', ' Signal')
signal = between(ap, 'Signal level=', ' dBm')
encryption = between(ap, 'Encryption key:', '\n').ljust(10)
essid = between(ap, 'ESSID:\"', '\"\n')
mode = between(ap, 'Mode:', '\n')
print(f'{address} | {channel} | {frequency} GHz | {quality} | {signal} dBm | {mode} | {encryption} | {essid}')