我编写 iwconfig,这样我就可以获得我的 lan ESSID 的名称和点访问的 mac,我想恢复他的两个字段以在脚本中使用,我可以在第一行,但我无法获得我想要的信息。
如何在 ubuntu 中使用该值 ESSID 和接入点
wlan0 IEEE 802.11bgn ESSID:“主页” 模式:管理频率:2.437 GHz 接入点:00:03:B6:K9:L1:9E
我需要帮助。谢谢。
尝试:
proc = Popen(['iwconfig'], stdout=PIPE, stderr=DN)
print "try de iwconfig %s"%proc
操作系统错误除外:
sys.exit("Could not execute iwconfig")
for line in proc.communicate()[0].split('\n'): print "line %s"%line if len(line) == 0:
continue # Isn't an empty string
if line[0] != ' ':
if 'IEEE 802.11' in line:
if "ESSID:\"" in line:
print line[ESSID][0]
if "Access Point:\"" in line:
print line[Access Point][0]
最佳答案
对于我的 iwconfig
输出,像这样的正则表达式似乎工作得很好:
from re import *
from subprocess import *
proc = Popen(['iwconfig'], stdout=PIPE)
intext=str(proc.communicate()[0])
m1=search('Access Point: [ABCDEF0123456789:]*',intext)
AP=m1.group(0).split(' ')[2]
print AP
m2=search('ESSID:".*" ',intext)
ESSID=m2.group(0).split('"')[1]
print ESSID
关于linux - 当我编写 iwconfig 时如何获取 ESSID 和 Access Point,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29492336/