如何获得我使用python连接的wifi路由器的BSSID?

时间:2016-11-23 03:16:50

标签: python wifi

我可以使用任何python库连接,或者有人可以告诉我如何在python中实现commandprompt的命令。

1 个答案:

答案 0 :(得分:1)

取决于操作系统。

from sys import platform
import subprocess
if platform == 'linux' or platform == 'linux2':
    # linux
   output = subprocess.check_output('iwgetid', '-r')
elif platform == 'darwin':
    # OS X
    ps = subprocess.Popen(('/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport', '-I'), stdout=subprocess.PIPE)
    output = subprocess.check_output(('awk', '/ SSID/ {print substr($0, index($0, $2))}'), stdin=ps.stdout)
elif platform == 'win32':
    output = subprocess.check_output("netsh wlan show interfaces")
    ps.wait()

print output