写了个 Python 脚本,监听附近网络 Wi-Fi 设备,通过邮件和微信进行消息推送 - V2EX
V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
easternslope
V2EX    Python

写了个 Python 脚本,监听附近网络 Wi-Fi 设备,通过邮件和微信进行消息推送

  •  1
     
  •   easternslope
    wangshub 2019-01-24 18:23:38 +08:00 5421 次点击
    这是一个创建于 2459 天前的主题,其中的信息可能已经有所发展或是发生改变。

    hmpa-pi

    代码地址 https://github.com/wangshub/hmpa-pi

    在树莓派上,利用 Wireshark 扫描附近网络 WiFi 设备,并对扫描结果通过邮件或者微信进行推送。

    临近春节回老家过年,家里没人,又不想安装摄像头监控,参考 howmanypeoplearearound 写了一个监测脚本,当有手机或其它 Wi-Fi 设备在附近时,通过邮件或者微信提醒。

    特性

    • [x] Wi-Fi 设备扫描
    • [x] 邮件提醒
    • [x] 微信提醒(Server 酱)
    • [ ] 陌生设备检测

    原理

    在 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-root sudo dpkg-reconfigure wireshark-common (select YES) sudo usermod -a -G wireshark ${USER:-root} newgrp wireshark 

    配置网卡

    • 如果是支持监听模式的网卡,可以直接运行

    • 如果刚好是 Rtl8192 + Raspberry Pi,需要先卸载 rtl8192 驱动,再加载 RTL8188 驱动

      #!/usr/bin/env bash uname -a # disable rtl8192 driver sudo depmod 4.14.79-v7+ sudo rmmod 8192cu sudo modprobe rtl8192cu # set RTL8188 monitor mode sudo ifconfig wlan1 down sudo iwconfig wlan1 mode monitor sudo ifconfig wlan1 up 

    运行代码

    下载代码

    git clone https://github.com/wangshub/hmpa-pi.git cd hmpa-pi/ && pip install -r requirements.txt 

    编辑配置文件

    cp config/config.py.example config/config.py vi config/config.py 

    参考配置

    adapte = 'wlan1' 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 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

    • MIT
    • 仅供学习和研究,切勿非法使用

    代码地址

    代码地址 https://github.com/wangshub/hmpa-pi

    18 条回复    2019-02-01 18:01:21 +08:00
    d5
        1
    d5  
       2019-01-24 18:30:44 +08:00
    nice,小星星送上
    sunnyadamm
        2
    sunnyadamm  
       2019-01-24 18:38:13 +08:00 via Android
    我能说我以前写过一个类似的么
    easternslope
        3
    easternslope  
    OP
       2019-01-24 18:41:30 +08:00
    @d5 谢谢
    easternslope
        4
    easternslope  
    OP
       2019-01-24 18:42:08 +08:00
    @sunnyadamm 感觉挺好玩儿的
    Vegetable
        5
    Vegetable  
       2019-01-24 18:42:11 +08:00 via iPhone
    这是重新发明了 WIFI 探针吗?去年公司拿来一块给我研究了一下,连上网就能自己向配置好点地址 push 附近设备的 Mac 地址
    gaocc
        6
    gaocc  
       2019-01-24 18:44:53 +08:00
    看着蛮 6 的,硬件需求具体是啥?
    easternslope
        7
    easternslope  
    OP
       2019-01-24 18:46:15 +08:00
    @gaocc 1 个树莓派或者 Mac/Linux,1 个支持监听模式的 USB wifi 模块
    gabon
        8
    gabon  
       2019-01-24 19:11:14 +08:00 via Android
    那个小路由器刷好 openwrt 感觉更方便
    easternslope
        9
    easternslope  
    OP
       2019-01-24 19:20:06 +08:00
    @gabon 好办法,应该可以找到类似 wireshark 这种扫描软件的 *.ipk 安装包
    sunnyadamm
        10
    sunnyadamm  
       2019-01-24 19:38:18 +08:00 via Android
    @easternslope 以前还写过类似局域网炸弹的东西
    easternslope
        11
    easternslope  
    OP
       2019-01-24 19:44:12 +08:00
    @sunnyadamm Love and Peace
    easternslope
        12
    easternslope  
    OP
       2019-01-24 20:23:50 +08:00
    注意保护个人隐私,在公共场所

    - 不要随意访问 Wi-Fi,还是用流量好
    - 关闭 Wi-Fi
    Neo
        13
    Neo  
       2019-01-25 08:52:10 +08:00   1
    这样弄成本高了些,找个闲置路由器把程序刷进去就行了
    Neo
        14
    Neo  
       2019-01-25 08:56:37 +08:00   1
    探针都是这样,即使不连热点,都能扫出这些,所以不是用不用公共 wifi 的问题,是做不做坏事的问题,要做坏事用流量基站那边也一样有记录
    Alfons
        15
    Alfons  
       2019-01-25 09:23:42 +08:00
    为啥不用 airodump 呢
    justin2018
        16
    justin2018  
       2019-01-25 16:57:05 +08:00
    @easternslope 楼主问哈 图例中你用的是哪款 usb 网卡 树莓派免驱不~ 谢谢了~
    easternslope
        17
    easternslope  
    OP
       2019-01-25 17:09:46 +08:00
    @justin2018 型号 RT3070,树莓派直接免驱能用,淘宝上很便宜
    tuomasi
        18
    tuomasi  
       2019-02-01 18:01:21 +08:00
    我准备只带个大钳子去你家
    关于     帮助文档     自助推广系统     博客     API     FAQ     Solana     2492 人在线   最高记录 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 26ms UTC 05:45 PVG 13:45 LAX 22:45 JFK 01:45
    Do have faith in what you're doing.
    ubao msn snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86