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
memoryone
V2EX  ›  Python

Python 有什么方法可以检测是否连接无线网吗?

  •  
  •   memoryone · 2022-09-13 22:34:06 +08:00 · 2084 次点击
    这是一个创建于 581 天前的主题,其中的信息可能已经有所发展或是发生改变。

    Pywifi 这个库现在好像使用不了,有什么其他方法检测有没有连接到无线网和自动连接指定 wifi 吗?

    8 条回复    2022-09-16 11:21:26 +08:00
    cubecube
        1
    cubecube  
       2022-09-13 23:53:46 +08:00
    直接执行 ip 命令就行?
    ila
        2
    ila  
       2022-09-14 00:17:27 +08:00 via Android
    遍历网卡
    ysc3839
        3
    ysc3839  
       2022-09-14 03:56:17 +08:00 via Android
    调系统 API 。
    Linux 下可能比较麻烦,因为有很多种网络管理器。NetworkManager 的话比较简单,用 D-Bus 接口即可。
    bytesfold
        4
    bytesfold  
       2022-09-14 08:52:25 +08:00 via iPhone
    Windows: netsh
    Ubuntu: nmcli
    webcape233
        5
    webcape233  
       2022-09-14 09:08:58 +08:00 via iPhone
    shell ,ip -br a ,wifi 网卡应该都是 wlanx
    chengyiqun
        6
    chengyiqun  
       2022-09-14 14:49:32 +08:00
    def get_wifi_ssid():
    scan_output = check_output([r"showSSID.cmd"])
    current_ssid = scan_output.decode().strip()
    return current_ssid
    chengyiqun
        7
    chengyiqun  
       2022-09-14 14:49:48 +08:00
    showSSID.cmd

    @echo off

    set x=None

    @for /f "tokens=1,2,3" %%i in ('netsh WLAN show interfaces') do (
    if [%%i]==[SSID] set x=%%k

    )

    echo %x%
    memoryone
        8
    memoryone  
    OP
       2022-09-16 11:21:26 +08:00
    我的是 mac 电脑我想用第三方库,有推荐实用的不,subprocess 这个库可以执行第三方命令,用这个库可行吗??
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1066 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 18:50 · PVG 02:50 · LAX 11:50 · JFK 14:50
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.