python pywifi

简介: python pywifi 模块

pywifi安装

pip install pywifi

下列代码判断是否有无限网卡

import pywifi
import sys
import time
from pywifi import const

def gic():
wifi=pywifi.PyWifi()#创建一个无线对象
ifaces=wifi.interifaces()[0]#取第一个无限网卡
if ifaces in [const.IFACE_DISCONNECTED,

                const.IFACE_INACTIVE]
  print('已连接')

else:

 print('未连接')

gic()
扫描附近的wifi

import pywifi
import sys
import time
from pywifi import const
def bies():
wifi=pywifi.PyWifi()#创建一个无限对象
ifaces=wifi.interifaces()[0]#取一个无限网卡
ifaces.scan()#扫描
bessis=ifaces.scan_results()
for data in bessis:

print(data.ssid)#输出wifi名称

尝试并连接wifi

import pywifi
import sys
import time
from pywfi import const

def deswifi():
wifi=pywifi.PyWifi()#创建一个wifi对象
ifaces=wifi.iinterifaces()[0]#取第一个无限网卡
print(ifaces.name())#输出无线网卡名称
ifaces.disconnect()#断开网卡连接
time.sleep(3)#缓冲3秒

profile=pywifi.profile()#配置文件
profile.ssid="TP-LINK_489"#wifi名称
profile.auth=const.AUTH_ASG_OPEN#需要密码
profile.akm.append(const.AKM_TYPE_WPA2SK)#加密类型
profile.cipher=const.CIPHER_TYPE_CCMP#加密单元

ifaces.remove_all_network_profiles()#删除其他配置文件
tmp_profile=ifaces.add_network_profile(profile)#加载配置文件

ifaces.connect(tmp_profile)#连接
time.sleep(10)#尝试10秒能否成功连接
isok=True
if ifaces.status()==const.IFACE_CONNECTED:
print("成功连接")
else:
print("失败")
ifaces.disconnect()#断开连接
time.sleep(1)
return isok

deswifi()

目录
相关文章
|
3天前
|
前端开发 应用服务中间件 Apache
Python的CherryPy
Python的CherryPy
40 3
|
12月前
|
Python
python实用篇
python实用篇
|
Python
python:哈么雷特
week6_2.py 请在...处补充代码 def getText():
88 0
|
缓存 算法 Python
用 Python 把坤坤动起来
最近看到一个 Up 主 Ele实验室 发布的一个视频:字符化视频是怎么做出来的,感觉很有意思。不如自己也实现一个来玩玩? 以前也没怎么写过 Python,只用来刷过 LeetCode。正好借这个机会再学一学 Python 吧。
用 Python 把坤坤动起来
|
SQL Java 关系型数据库
数据持久化技术(Python)的使用
- 传统数据库连接方式:mysql(PyMySQL) - ORM 模型:SQLAlchemy MyBatis、 Hibernate ## PyMySQL 安装: ``` pip install pymysql ``` ## 简单使用 利用 pymysql.connect 建立数据库连接并执行 SQL 命令(需要提前搭建好数据库): ``` import pymysql db =
|
Java Python Windows
|
Web App开发 Linux 程序员