linux - 当我编写 iwconfig 时如何获取 ESSID 和 Access Point

标签 linux python-2.7 networking

我编写 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/

相关文章:

python - 如何在某个字符之前获取字符串的最后一部分?

java - Android中如何在不锁定UI线程的情况下等待?

linux - 如何在 crontab 似乎被删除的 cron 作业中 grep 行?

c - pthread_kill 异步信号在 Linux 上安全吗?

C# 计时器分辨率 : Linux (mono, dotnet 核心)与 Windows

python - 如何在python中将对象数组转换为普通数组

python-2.7 - celery , flask sqlalchemy : DatabaseError: (DatabaseError) SSL error: decryption failed or bad record mac

c - getaddrinfo addrinfo 结果在堆栈或堆中

c# - 运行多个线程时程序执行缓慢

linux - Perl 脚本将换行符添加到文本文件末尾