Is there any way to access OS X wi-fi data using Python? (Signal strength, for example)

烈酒焚心 提交于 2020-02-01 21:46:12

问题


I am just curious whether it would be possible to use any Python tools to poll wi-fi signal strength in OS X. Most of my searches are just yielding Python tools for Linux, but none for OS X.

If not, are there any other ways to get such data programmatically?


回答1:


The answer to this question describes how to load the CoreWLAN framework. Once you've done that, you can use the CWInterface class to find the RSSI, amongst other stats:

import objc
objc.loadBundle('CoreWLAN',
                bundle_path='/System/Library/Frameworks/CoreWLAN.framework',
                module_globals=globals())

for iname in CWInterface.interfaceNames():
  interface = CWInterface.interfaceWithName_(iname)
  print """
Interface:      %s
SSID:           %s
Transmit Rate:  %s
Transmit Power: %s
RSSI:           %s""" % (iname, interface.ssid(), interface.transmitRate(),
                         interface.transmitPower(), interface.rssi())

See the CWInterface docs for the full list of available properties.




回答2:


For mac there is a Command line tool called airport. You can manually adjust any wi-fi settings, network card settings, troubleshoot networks, change security types used on a connection, capture packets into a pcap file, join and leave networks, forget a wifi network, prioritize routers and networks, see signal strength and interference etc.

Its usually in here - /System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport

You can just type this for help

airport
airport -h

Using this and subprocess together you should be able to do most of these things in python



来源:https://stackoverflow.com/questions/15169022/is-there-any-way-to-access-os-x-wi-fi-data-using-python-signal-strength-for-e

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!