python-3.x 如何为CoreWLAN pyobjc Package 器启用位置服务以获取bssid?

xfb7svmp  于 2023-03-31  发布在  Python
关注(0)|答案(1)|浏览(105)

我使用pyobjc Package 器来扫描网络:

import objc
objc.loadBundle(
    "CoreWLAN",
    bundle_path="/System/Library/Frameworks/CoreWLAN.framework",
    module_globals=globals()
)
from CoreWLAN import CWNetwork, CWWiFiClient
client = CWWiFiClient.sharedWiFiClient()
iface = client.interfaceWithName_("en0")
networks, error = iface.scanForNetworksWithName_error_(
    None,
    None,
)
print(networks)

并得到
{(〈CWNetwork:0x7ff7a64040d0〉[ssid=FRITZ!Box 7520 HT,bssid=(null),security=WPA2 Personal,rssi= -84,channel=〈CWChannel:0x7ff79644b800〉[channelNumber=116(5GHz),channelWidth={80MHz}],ibss=0],〈CWNetwork:0x7ff7a64447d0〉[ssid=FRITZ$Box 7412,bssid=(null),security=WPA/WPA2 Personal,rssi= -52,channel=〈CWChannel:0x7ff7964054c0〉[channelNumber=11(2GHz),channelWidth={20MHz}],ibss=0],...)}
正如您可能看到的,bssid为null。此外,正如这里所指出的,这是预期的行为:https://developer.apple.com/forums/thread/119490?answerId=387785022#387785022
如何启用此代码的位置服务以获取bssid?

**UPD:找到解决方案!**github.com/ronaldoussoren/pyobjc/issues/484

rhfm7lfc

rhfm7lfc1#

这是我用来为Python生成位置服务权限请求的脚本:

import CoreLocation
from time import sleep

location_manager = CoreLocation.CLLocationManager.alloc().init()
location_manager.startUpdatingLocation()

max_wait = 60
# 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:
        exit("Unable to obtain authorization, exiting")
    sleep(1)

coord = location_manager.location().coordinate()
lat, lon = coord.latitude, coord.longitude
print("Your location is %f, %f" % (lat, lon))

在我对MacOS 13.2的测试中,如果Python有位置服务权限,那么你可以看到BSSID。这似乎是一个错误修复,因为这应该是预期的行为,因为他们开始在MacOS 10.15中隐藏BSSID。

相关问题