hmpa-pi
在樹莓派上,利用 Wireshark 掃描附近網絡 WiFi 設備,並對掃描結果通過郵件或者微信進行推送。
臨近春節回老家過年,家裏沒人,又不想安裝攝像頭監控,參考 howmanypeoplearearound 寫了一個監測腳本,當有手機或其它 Wi-Fi 設備在附近時,可以通過郵件或者微信提醒。
特性
原理
在 Wi-Fi 網絡中,無線網卡是以廣播模式發射信號的。當無線網卡將信息廣播出去後,所有的設備都可以接收到該信息。將無線網卡設置爲監聽模式後,就可以捕獲到該網卡接收範圍的所有數據包。
通過這些數據包,就可以掃描出附近 Wi-Fi 的網絡內的設備與信號強度。
監聽模式的網卡
一些支持監聽模式的網卡
wifi-adapter-that-supports-monitor-mode
軟件安裝
Mac
brew install wireshark brew cask install wireshark-chmodbpf
Linux 或 Raspberry Pi
sudo apt-get install tshark# run as non-rootsudo dpkg-reconfigure wireshark-common (select YES)sudo usermod -a -G wireshark ${USER:-root}newgrp wireshark
# run as non-root
sudo dpkg-reconfigure wireshark-common (select YES)
sudo usermod -a -G wireshark ${USER:-root}
newgrp wireshark
配置網卡
運行代碼
下載代碼
git clone https://github.com/wangshub/hmpa-pi.git cd hmpa-pi/ && pip install -r requirements.txt
cd hmpa-pi/ && pip install -r requirements.txt
編輯配置文件
cp config/config.py.example config/config.pyvi config/config.py
參考配置
adapter = 'wlan1'use_email = Trueemail = {"host": "smtp.163.com", "port": 465, "user": "[email protected]", "password": "xxxxxxxxxx", "to_user": "[email protected]"}use_wechat = Trueserverchan = {"sckey": "xxxxxxxxxxxxxxxxxxxxx"}known_devices = {"94:65:2d:xx:xx:xx": "my cellPhone", "dc:a4:ca:xx:xx:xx": "my Mac", "b8:27:eb:xx:xx:xx": "my raspberry"}
use_email = True
email = {"host": "smtp.163.com",
"port": 465,
"user": "[email protected]",
"password": "xxxxxxxxxx",
"to_user": "[email protected]"}
use_wechat = True
serverchan = {"sckey": "xxxxxxxxxxxxxxxxxxxxx"}
known_devices = {"94:65:2d:xx:xx:xx": "my cellPhone",
"dc:a4:ca:xx:xx:xx": "my Mac",
"b8:27:eb:xx:xx:xx": "my raspberry"}
運行
python main.py
消息推送
運行結果
2019-01-24 07:37:01.211617 一共發現了 67 臺設備Known Devices:- my cellPhone- my raspberry- my macAll Devices:- 00:e0:70:3e:xx:xx 14 DH TECHNOLOGY- 94:65:2d:91:xx:xx 14 OnePlus Technology (Shenzhen) Co., Ltd- dc:d9:16:7e:xx:xx -12 HUAWEI TECHNOLOGIES CO.,LTD- b8:27:eb:12:xx:xx -20 Raspberry Pi Foundation- 98:01:a7:eb:xx:xx -40 Apple, Inc.- 20:5d:47:44:xx:xx -44 vivo Mobile Communication Co., Ltd.- ac:b5:7d:5f:xx:xx -46 Liteon Technology Corporation- 04:03:d6:1f:xx:xx -47 Nintendo Co.,Ltd- d4:ee:07:55:xx:xx -48 HIWIFI Co., Ltd.- 44:6e:e5:63:xx:xx -51 HUAWEI TECHNOLOGIES CO.,LTD- 14:75:90:8d:xx:xx -51 TP-LINK TECHNOLOGIES CO.,LTD.- 34:96:72:1d:xx:xx -56 TP-LINK TECHNOLOGIES CO.,LTD.- d8:cb:8a:74:xx:xx -57 Micro-Star INTL CO., LTD.- 40:8d:5c:21:xx:xx -57 GIGA-BYTE TECHNOLOGY CO.,LTD.- 6c:59:40:25:xx:xx -58 SHENZHEN MERCURY COMMUNICATION TECHNOLOGIES CO.,LTD.More ...
Known Devices:
- my cellPhone
- my raspberry
- my mac
All Devices:
- 00:e0:70:3e:xx:xx 14 DH TECHNOLOGY
- 94:65:2d:91:xx:xx 14 OnePlus Technology (Shenzhen) Co., Ltd
- dc:d9:16:7e:xx:xx -12 HUAWEI TECHNOLOGIES CO.,LTD
- b8:27:eb:12:xx:xx -20 Raspberry Pi Foundation
- 98:01:a7:eb:xx:xx -40 Apple, Inc.
- 20:5d:47:44:xx:xx -44 vivo Mobile Communication Co., Ltd.
- ac:b5:7d:5f:xx:xx -46 Liteon Technology Corporation
- 04:03:d6:1f:xx:xx -47 Nintendo Co.,Ltd
- d4:ee:07:55:xx:xx -48 HIWIFI Co., Ltd.
- 44:6e:e5:63:xx:xx -51 HUAWEI TECHNOLOGIES CO.,LTD
- 14:75:90:8d:xx:xx -51 TP-LINK TECHNOLOGIES CO.,LTD.
- 34:96:72:1d:xx:xx -56 TP-LINK TECHNOLOGIES CO.,LTD.
- d8:cb:8a:74:xx:xx -57 Micro-Star INTL CO., LTD.
- 40:8d:5c:21:xx:xx -57 GIGA-BYTE TECHNOLOGY CO.,LTD.
- 6c:59:40:25:xx:xx -58 SHENZHEN MERCURY COMMUNICATION TECHNOLOGIES CO.,LTD.
More ...
TODO
參考鏈接
License
代碼地址
https://github.com/wangshub/hmpa-pi