-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathpinpoint_scan.py
73 lines (64 loc) · 2.63 KB
/
pinpoint_scan.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/usr/local/bin/managed_python3
#
# Copyright John E. Lockwood (2024)
#
# pinpoint_scan.py is a replacement for Apple's airport binary which has been deprecated in macOS Sonoma 14.4
# it produces a scan report of available SSIDs in the same format previously available from Apple's airport tool
# Due to additional changes to CoreWLAN made by Apple it is now necessary to enable access to Location Services for Python
#
# see https://github.com/jelockwood/pinpoint
# Many thanks in particular go to @thewade. He greatly helped with how to format the output as required, how to retrieve
# certain fields of information via CoreWLAN, and also especially helped with the fact that - perhaps counter-intuitively
# Location Services has to be enabled in order to also retreive certain fields of information.
#
# The code to check Location Services is his - I have merely commented out a line
# Checks that Location Services is enabled for Python and exit with error if not
import CoreLocation
import sys
from time import sleep
location_manager = CoreLocation.CLLocationManager.alloc().init()
location_manager.startUpdatingLocation()
max_wait = 6
# Get the current authorization status for Python
for i in range(1, max_wait):
authorization_status = location_manager.authorizationStatus()
if authorization_status == 3 or authorization_status == 4:
# print("Python has been authorized for location services")
break
if i == max_wait-1:
sys.exit("Unable to obtain Location Services authorization, exiting")
sleep(1)
# End checking of Location Services
import objc
objc.loadBundle(
"CoreWLAN",
bundle_path="/System/Library/Frameworks/CoreWLAN.framework",
module_globals=globals()
)
import CoreWLAN
import re
from CoreWLAN import CWNetwork, CWWiFiClient
iface = CoreWLAN.CWInterface.interface()
networks, error = iface.scanForNetworksWithName_error_(
None,
None,
)
print(f"{'SSID' : >32} {'BSSID' : <17} RSSI CHANNEL HT CC SECURITY")
for i in networks:
if i.ssid() is None:
continue
ssidstr = i.ssid().rjust(32)
if not i.bssid():
bssidstr = " ".ljust(17)
if i.bssid():
bssidstr = i.bssid().ljust(17)
rssistr = str(i.rssiValue()).ljust(4)
channelstr = str(i.channel()).ljust(7)
supportsHT = 'Y' if i.fastestSupportedPHYMode() >= CoreWLAN.kCWPHYMode11n else 'N'
supportsHTstr = supportsHT.ljust(2)
if not i.countryCode():
countrystr = "--".ljust(2)
if i.countryCode():
countrystr = i.countryCode().ljust(2)
securitystr = re.search('security=(.*?),', str(i)).group(1)
print(ssidstr,bssidstr,rssistr,channelstr,supportsHTstr,countrystr,securitystr)