Pywifi - python用法

凉沐流风 - 枫

一、目录

一、目录

二、前言

三、pywifi的介绍与下载

四、pywifi基础

五、pywifi详细讲解

六、原本教程(英文版)


二、前言

本教程原本是我寄存在的一个python程序,所以所有的讲解都是在代码中的,若有不便,敬请谅解

原本我所书写的文件为英文版,教程可见下,若有疑问,可加Q:2633748531进行询问

三、pywifi的介绍与下载

1.介绍:pywifi是在python中一个用于操作无线接口的模块,可以跨平台使用,Windows和Linux都支持

2.下载:①pip下载:打开命令提示符,输入下载命令:

pip install pywifi

由于此模块基于comtypes模块,因此同时需要下载此模块:

pip install comtypes

对于PyCharm,则直接下载两个模块即可

四、pywifi基础

#  引入pywifi库及所带常量库
import pywifi
from pywifi import const, Profile#  1. 基础#  获取网卡接口
wifi = pywifi.PyWiFi()#  得到第一个无线网卡
ifaces = wifi.interfaces()[0]#  切断网卡连接
ifaces.disconnect()#  获取wifi的连接状态
wifistatus = ifaces.status()#  检查wifi是否处于切断状态
if wifistatus == const.IFACE_DISCONNECTED:#  网卡已被切断pass#  如果网卡没有被切断
#  或者使用 " if wifistatus == const.IFACE_CONNECTED: "else:#  已连接wifipass#  如果已经切断网卡,一般执行下述操作
if wifistatus == const.IFACE_DISCONNECTED:#  设置wifi连接文件profile: Profile = pywifi.Profile()#  你要连接的网络的名称profile.ssid = "    "#  网卡的开放状态#  " Auth - AP "的验证算法profile.auth = const.AUTH_ALG_OPEN#  wifi的加密算法#  通常的加密算法值为 " WPA "#  选择wifi的加密方式#  " Akm - AP "的密钥管理profile.akm.append(const.AKM_TYPE_WPA2PSK)#  加密单元#  " Cipher - AP "的密码类型profile.cipher = const.CIPHER_TYPE_CCMP#  设置密码password = "   "#  回调密码(wifi密码)#  如果没有密码,则设置值为 " CIPHER_TYPE_NONE "profile.key = password#  删除已连接的所有wifi文件ifaces.remove_all_network_profiles()#  加载新的wifi连接文件tep_profile = ifaces.add_network_profile(profile)#  连接上面的wifi文件ifaces.connect(tep_profile)#  如果wifi已连接if ifaces.status() == const.IFACE_CONNECTED:print(True)#  如果仍未连接else:print(False)

五、pywifi详细讲解

#  2.提高#  获取wifi接口名称
name = ifaces.name()#  扫描wifi ( AP )
ifaces.scan()#  查看上面的wifi扫描结果 ( 返回值为列表 )
result = ifaces.scan_results()#  删除所有的AP配置文件
#  目的是为了接下来的连接
ifaces.remove_all_network_profiles()#  返回配置文件的列表
files = ifaces.network_profiles()#  设置配置文件的名字
ifaces.add_network_profile(profile)#  连接wifi
ifaces.connect(profile)#  断开wifi
ifaces.disconnect()#  wifi的连接状态
ifaces.status()#  配置文件
profile = pywifi.Profile()#  配置文件的方法
#  ssid  auth  akm  cipher  key
#  这些的详细讲解可看基础#  pywifi中const的量#  const.IFACE_DISCONNECTED = 0
#  const.IFACE_SCANNING = 1
#  const.IFACE_INACTIVE = 2
#  const.IFACE_CONNECTING = 3
#  const.IFACE_CONNECTED = 4#  Auth - AP
var1 = const.AUTH_ALG_OPEN
var2 = const.AUTH_ALG_SHARED#  Akm - AP
#  不安全的方法
var3 = const.AKM_TYPE_NONE
#  WPA的方法
var4 = const.AKM_TYPE_WPAPSK
#  WPA2的方法
var5 = const.AKM_TYPE_WPA2PSK
#  对于企业的方法
var6 = const.AKM_TYPE_WPA
var7 = const.AKM_TYPE_WPA2#  Cipher - AP
var8 = const.CIPHER_TYPE_NONE
var9 = const.CIPHER_TYPE_WEP
var10 = const.CIPHER_TYPE_TKIP
var11 = const.CIPHER_TYPE_CCMP

六、原本教程(英文版)

#  Import the module of PyWifi
import pywifi
from pywifi import const, Profile#  1. Basic#  Get the network card interface
wifi = pywifi.PyWiFi()#  Get the first wireless network card
ifaces = wifi.interfaces()[0]#  Disconnect the network card
ifaces.disconnect()#  Get the connection state of wifi
wifistatus = ifaces.status()#  Check if disconnect the wifi
if wifistatus == const.IFACE_DISCONNECTED:#  The network card disconnectpass#  If the network card has already connected
#  Or use the " if wifistatus == const.IFACE_CONNECTED: "else:#  Have already connected the wifipass#  If you have already disconnect the network card, do the below
if wifistatus == const.IFACE_DISCONNECTED:#  Set up the file of wifi connectionprofile: Profile = pywifi.Profile()#  The name of wifi which you want to connectprofile.ssid = "TP-LINKwangqing"#  The opening state of the network card#  The authentication algorithm of " Auth - AP"profile.auth = const.AUTH_ALG_OPEN#  The encryption algorithm of wifi#  The encryption algorithm of common wifi is " WPA "#  Choose the encryption way of wifi#  The key management type of " Akm - AP "profile.akm.append(const.AKM_TYPE_WPA2PSK)#  Encryption unit#  The password type of " Cipher - AP "profile.cipher = const.CIPHER_TYPE_CCMP#  Set the passwordpassword = "wangzijia123456"#  Call the password ( the password of wifi)#  If there's no password, set the value " CIPHER_TYPE_NONE "profile.key = password#  Delete all the file of wifi which has already connectedifaces.remove_all_network_profiles()#  Loading the new file of connectiontep_profile = ifaces.add_network_profile(profile)#  Connect the new file that aboveifaces.connect(tep_profile)#  If the wifi has already connectedif ifaces.status() == const.IFACE_CONNECTED:print(True)#  If it has disconnected yetelse:print(False)#  2.Improvement#  Get the name of wifi interface
name = ifaces.name()#  Scan the wifi ( AP )
ifaces.scan()#  Look the result of scanning ( list )
result = ifaces.scan_results()#  Delete all the setting files of AP
#  In order to the next connect
ifaces.remove_all_network_profiles()#  Return the list of setting files
files = ifaces.network_profiles()#  Set the name of setting file
ifaces.add_network_profile(profile)#  Connect the wifi
ifaces.connect(profile)#  Disconnect the wifi
ifaces.disconnect()#  The connection state of wifi
ifaces.status()#  Const in pywifi#  const.IFACE_DISCONNECTED = 0
#  const.IFACE_SCANNING = 1
#  const.IFACE_INACTIVE = 2
#  const.IFACE_CONNECTING = 3
#  const.IFACE_CONNECTED = 4#  Set up the file
profile = pywifi.Profile()#  The way to set up the file
#  ssid  auth  akm  cipher  key
#  These look above#  Auth - AP
var1 = const.AUTH_ALG_OPEN
var2 = const.AUTH_ALG_SHARED#  Akm - AP
#  No safe mode
var3 = const.AKM_TYPE_NONE
#  The mode of WPA
var4 = const.AKM_TYPE_WPAPSK
#  The mode of WPA2
var5 = const.AKM_TYPE_WPA2PSK
#  For business
var6 = const.AKM_TYPE_WPA
var7 = const.AKM_TYPE_WPA2#  Cipher - AP
var8 = const.CIPHER_TYPE_NONE
var9 = const.CIPHER_TYPE_WEP
var10 = const.CIPHER_TYPE_TKIP
var11 = const.CIPHER_TYPE_CCMP

Pywifi用法 - python相关推荐

  1. python join函数用法-Python join()函数

    今天写python 100例时,有个题目是大致是这样的:已知输入形式是1+3+2+1,要求输出形式为1+1+2+3 一开始思路是将输入的字符串用split()函数划分成数组,在对数组进行排序,再用fo ...

  2. python中path的用法,python中path的用法

    如何将python的路径加到path中 方法一:函数添加 1 import sys 2 查看sys.path 3 添加sys.path.append("c:\\") 方法二:修改环 ...

  3. map函数的用法python,详解Python map函数及Python map()函数的用法

    python map函数 map()函数 map()是 Python 内置的高阶函数,它接收一个函数 f 和一个 list,并通过把函数 f 依次作用在 list 的每个元素上,得到一个新的 list ...

  4. python中readlines函数用法,python中read() readline()以及readlines()用法

    我们谈到"文本处理"时,我们通常是指处理的内容.Python 将文本文件的内容读入可以操作的字符串变量非常容易.文件对象提供了三个"读"方法: .read(). ...

  5. 反转字符串/列表、改变递归次数限制、else用法...Python 冷知识(四)

    本文转载自Python编程时光(ID:Python-Time) 冷知识系列,已经更新至第四篇.前三篇传送门在此,还没阅读的可以学习一下. 谈谈 Python 那些不为人知的冷知识(一) 谈谈 Pyth ...

  6. python items函数用法,Python中dictionary items()系列函数的用法实例

    本文实例讲述了Python中dictionary items()系列函数的用法,对Python程序设计有很好的参考借鉴价值.具体分析如下: 先来看一个示例: import html # availab ...

  7. python中int用法,Python中int()函数的用法浅析

    int()是Python的一个内部函数 Python系统帮助里面是这么说的 >>> help(int) Help on class int in module __builtin__ ...

  8. python中match的六种用法,python 正则函数match()和search()用法示例

    这篇文章主要为大家详细介绍了python 正则函数match()和search()用法示例,具有一定的参考价值,可以用来参考一下. 对python正则表达式函数match()和search()的区别详 ...

  9. python冒号用法-python 列表中[ ]中冒号‘:’的作用

    中括号[ ]:用于定义列表或引用列表.数组.字符串及元组中元素位置 list1 = ["physics", "chemistry", 1997, 2000] l ...

  10. python中for in的用法python中for in的用法

    for in 说明:也是循环结构的一种,经常用于遍历字符串.列表,元组,字典等 格式: 1 2 for x in y:     循环体 执行流程:x依次表示y中的一个元素,遍历完所有元素循环结束. 例 ...

最新文章

  1. Science子刊:植物所杨元合组揭示矿物保护和微生物属性对冻土碳动态的关键调控作用...
  2. python小游戏源码-Python小游戏之300行代码实现俄罗斯方块
  3. SQLServer 事务复制中使用脚本添加某个对象的发布
  4. 前端学习(3115):react-hello-初始化state
  5. matlab ann-bp分类器,利用matlab真的BP-ANN分类器设计.doc
  6. pythonrange函数用法_python range()函数详细用法
  7. autosar中bsw架构组成_AUTOSAR分层架构深度解析
  8. 阶段3 1.Mybatis_03.自定义Mybatis框架_5.自定义Mybatis的编码-创建两个默认实现类并分析类之间的关系...
  9. c语言第三章作业3.13,c语言谭浩强第1章至第3章测试试题
  10. go 对象json转map
  11. 美团面试小感——认知撑起的格局
  12. JTT808、JTT1078、TJSATL主动安全踩坑记录
  13. asp.net使用MailMessage发送邮件的方法
  14. python matplotlib画饼形图
  15. java简单实现在线资源多线程下载,断点续存,限制最大正在下载数
  16. 爬虫学习笔记,从基础到部署。
  17. mysql vs创建表_MYSQL基础三--表的操作一
  18. 清默网络——CISCO ASA SSL ***详解
  19. 随机算法java实现(同生日问题以及扑克牌24数问题)
  20. yapi 全局变量使用_yapi 中 mock JSONP 接口响应的方法

热门文章

  1. mysql 实现字符串的拼接
  2. 【ASP.NET】QQ登录,新浪微博登录。
  3. Ubuntu安装ffmpeg教程
  4. Python3使用xpath爬取豆丁网文档
  5. excel表格坐标导入cad怎样操作?
  6. SpringCloud 与 SpringBoot 微服务 架构 | 面试题及答案详解
  7. oracle rman在线备份,Oracle的RMAN备份与恢复脚本
  8. 吴恩达深度学习环境配置
  9. 计算机显示器刷新率怎么调,显示器刷新率怎么超频?电脑显示器提高屏幕刷新率超频教程...
  10. 如何检查计算机是否超频了,如何判断电脑是否支持超频?知识点get