国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > Python > 正文

DIY個(gè)人智能家庭網(wǎng)關(guān)—— python篇之獲取手機(jī)WIFI連接(上線/下線)狀態(tài)

2019-11-06 09:30:41
字體:
供稿:網(wǎng)友

如果需要根據(jù)自己的手機(jī)在連接或斷開路由器WIFI時(shí)觸發(fā)某個(gè)動(dòng)作,可以通過iw命令定時(shí)查詢手機(jī)的連接狀態(tài),執(zhí)行如下命令可以列出所有連接到路由器WIFI的設(shè)備,

root@OpenWrt:~# iw dev wlan0 station dumpStation e0:ac:cb:b1:ca:ba (on wlan0)        inactive time:  27010 ms        rx bytes:       198087        rx packets:     1417        tx bytes:       843928        tx packets:     969        tx retries:     66        tx failed:      4        signal:         -70 dBm        signal avg:     -70 dBm        tx bitrate:     72.2 MBit/s MCS 7 short GI        rx bitrate:     24.0 MBit/s        expected throughput:    34.84Mbps        authorized:     yes        authenticated:  yes        PReamble:       short        WMM/WME:        yes        MFP:            no        TDLS peer:      noStation 04:52:f3:87:cf:77 (on wlan0)        inactive time:  620 ms        rx bytes:       316840        rx packets:     3260        tx bytes:       419569        tx packets:     1576        tx retries:     91        tx failed:      0        signal:         -78 dBm        signal avg:     -79 dBm        tx bitrate:     144.4 MBit/s MCS 15 short GI        rx bitrate:     24.0 MBit/s        expected throughput:    43.20Mbps        authorized:     yes        authenticated:  yes        preamble:       short        WMM/WME:        yes        MFP:            no        TDLS peer:      noStation 94:94:26:9f:cc:fa (on wlan0)        inactive time:  25760 ms        rx bytes:       19497        rx packets:     312        tx bytes:       28507        tx packets:     137        tx retries:     1        tx failed:      0        signal:         -72 dBm        signal avg:     -71 dBm        tx bitrate:     57.8 MBit/s MCS 5 short GI        rx bitrate:     24.0 MBit/s        expected throughput:    30.29Mbps        authorized:     yes        authenticated:  yes        preamble:       short        WMM/WME:        yes        MFP:            no        TDLS peer:      noStation b0:d5:9d:61:3a:1a (on wlan0)        inactive time:  280 ms        rx bytes:       92157        rx packets:     919        tx bytes:       73302        tx packets:     615        tx retries:     457        tx failed:      78        signal:         -84 dBm        signal avg:     -87 dBm        tx bitrate:     39.0 MBit/s MCS 4        rx bitrate:     58.5 MBit/s MCS 6        expected throughput:    23.180Mbps        authorized:     yes        authenticated:  yes        preamble:       short        WMM/WME:        yes        MFP:            no        TDLS peer:      noStation a8:1b:5a:b7:e0:03 (on wlan0)        inactive time:  10750 ms        rx bytes:       106382        rx packets:     679        tx bytes:       97932        tx packets:     300        tx retries:     20        tx failed:      2        signal:         -54 dBm        signal avg:     -57 dBm        tx bitrate:     65.0 MBit/s MCS 7        rx bitrate:     6.0 MBit/s        expected throughput:    32.125Mbps        authorized:     yes        authenticated:  yes        preamble:       short        WMM/WME:        yes        MFP:            no        TDLS peer:      no如果只要MAC地址,可以過濾一下

root@OpenWrt:~# iw dev wlan0 station dump | grep StationStation e0:ac:cb:b1:ca:ba (on wlan0)Station 04:52:f3:87:cf:77 (on wlan0)Station 94:94:26:9f:cc:fa (on wlan0)Station b0:d5:9d:61:3a:1a (on wlan0)Station a8:1b:5a:b7:e0:03 (on wlan0)和路由器頁面上的一樣

確定自己是哪一個(gè)MAC地址后則可以進(jìn)一步進(jìn)行過濾,如下

如果過濾后還有輸出結(jié)果說明手機(jī)已經(jīng)連上了路由器,沒有輸出結(jié)果說明手機(jī)沒有連上路由器

如下是python代碼

#!/usr/bin/env python# -*- coding: utf-8 -*- import timeimport subprocessfrom time import sleepmac = "a8:1b:5a:b7:e0:03"cmd = 'iw dev wlan0 station dump | grep Station'while True:  obj = subprocess.Popen(cmd,stdout=subprocess.PipE,stderr=subprocess.PIPE,shell=True)  obj.wait()  state = 'offline'  lines = obj.stdout.readlines()  for str in lines:										  	if str.find(mac) > 0:  		state = 'online'  		break  print "phone %s %s"%(mac,state)  time.sleep(2)運(yùn)行輸出結(jié)果:


發(fā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 贺州市| 惠水县| 奉贤区| 华坪县| 定兴县| 汾西县| 江川县| 扎鲁特旗| 巩留县| 蓝山县| 新田县| 兴和县| 会宁县| 定襄县| 秦安县| 砚山县| 青州市| 商水县| 河间市| 腾冲县| 汽车| 郧西县| 海晏县| 东海县| 冷水江市| 梅河口市| 始兴县| 柘城县| 鄄城县| 武鸣县| 广德县| 通辽市| 凭祥市| 泗洪县| 巴南区| 喀喇沁旗| 双鸭山市| 电白县| 新泰市| 乌审旗| 策勒县|