首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在编写iwconfig时获得ESSID和Access Point

如何在编写iwconfig时获得ESSID和Access Point
EN

Stack Overflow用户
提问于 2015-04-07 13:02:57
回答 1查看 354关注 0票数 0

我写iwconfig是为了让我的lan ESSID和mac的名字是point acess,我想恢复他的两个字段,以便在第一行的脚本中使用,但是我不能得到我想要的信息。

如何使瓦雷乌斯·埃西德和接入点

wlan0 IEEE802.11bgn ESSID:“家庭”模式:托管频率:2.437 GHz接入点: 00:03:B6:K9:L1:9E

我需要帮助。谢谢。

尝试:

代码语言:javascript
复制
  proc = Popen(['iwconfig'], stdout=PIPE, stderr=DN)
  print "try de iwconfig %s"%proc

除了OSError:

代码语言:javascript
复制
  sys.exit("Could not execute iwconfig")

对于proc.communicate().split(‘\n’)中的行:打印"line %s"%line如果len(行) == 0:

代码语言:javascript
复制
           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]
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-04-07 14:51:36

对于我的iwconfig输出,这样的正则表达式似乎运行得很好:

代码语言:javascript
复制
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
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/29492336

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档