Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- # Filename: netsh_wlan_tool_1.0.1.py
- # Version: 1.0.1
- # Author: Jeoi Reqi
- """
- netsh_wlan_tool.py
- Description:
- This script provides a command-line interface for managing Wi-Fi networks on Windows systems using the 'netsh wlan' command.
- Requirements:
- - Python 3.x
- - Windows operating system
- - Python interpreter installed and configured correctly
- Usage:
- - Run the script in a terminal or command prompt.
- - Follow the on-screen menu prompts to perform various Wi-Fi network operations.
- Functions:
- 1. show_available_networks():
- - Displays a list of available Wi-Fi networks along with their BSSID information.
- 2. show_wifi_password(profile_name):
- - Displays the password for a specified Wi-Fi profile.
- 3. connect_to_profile(profile_name):
- - Connects to a specified Wi-Fi profile.
- 4. get_all_data():
- - Retrieves and displays all stored Wi-Fi profile names and passwords.
- Additional Notes:
- - Ensure that the script is executed with appropriate permissions to interact with the Wi-Fi subsystem.
- - Some functions may require administrative privileges to execute successfully.
- - Use caution when connecting to Wi-Fi networks or displaying passwords, as sensitive information may be exposed.
- """
- import subprocess
- def list_wifi_profiles():
- """
- Retrieve a list of all Wi-Fi profiles stored on the system.
- Returns:
- list: A list of all Wi-Fi profile names.
- """
- try:
- output = subprocess.check_output(["netsh", "wlan", "show", "profiles"], text=True)
- profiles = [line.split(":")[1].strip() for line in output.splitlines() if "All User Profile" in line]
- return profiles
- except subprocess.CalledProcessError as e:
- print(f"\nError listing Wi-Fi profiles:\n- {e}")
- return []
- def get_wifi_password(profile_name):
- """
- Retrieve the password for a specified Wi-Fi profile.
- Args:
- profile_name (str): The name of the Wi-Fi profile.
- Returns:
- str: The password of the Wi-Fi profile, or None if not found.
- """
- try:
- command = ["netsh", "wlan", "show", "profile", f'name="{profile_name}"', "key=clear"]
- output = subprocess.check_output(command, universal_newlines=True)
- password_line = [line for line in output.splitlines() if "Key Content" in line][0]
- password = password_line.split(":")[-1].strip()
- if password.lower() == "passphrase":
- return "\nPassword is hidden\n"
- else:
- return password
- except subprocess.CalledProcessError:
- return None
- def show_available_networks():
- """
- Display all the available Wi-Fi networks with BSSID information.
- """
- try:
- output = subprocess.check_output(["netsh", "wlan", "show", "networks", "mode=bssid"], stderr=subprocess.STDOUT)
- print(output.decode("utf-8"))
- except subprocess.CalledProcessError as e:
- print("\nError:", e.output.decode("utf-8"))
- except Exception as ex:
- print("\nAn unexpected error occurred:", ex)
- def show_wifi_password(profile_name):
- """
- Display the Wi-Fi password for the specified profile.
- Args:
- profile_name (str): The name of the Wi-Fi profile.
- """
- try:
- password = get_wifi_password(profile_name)
- if password:
- print(f"\n\tWi-Fi Password:\n\t- {password}")
- else:
- print("\nWi-Fi Password not found.")
- except subprocess.CalledProcessError as e:
- print("\nError:\n\t- ", e)
- def connect_to_profile(profile_name):
- """
- Connect to the specified Wi-Fi profile.
- Args:
- profile_name (str): The name of the Wi-Fi profile to connect to.
- """
- try:
- # Display currently connected Wi-Fi network
- output = subprocess.check_output(["netsh", "wlan", "show", "interfaces"], text=True)
- connected_network = [line.split(":")[1].strip() for line in output.splitlines() if "SSID" in line]
- print("\nCurrently connected Wi-Fi network:", connected_network[0])
- # Check if the profile exists and get its password
- password = get_wifi_password(profile_name)
- # Prompt the user for the profile name
- print("\nConnect to Wi-Fi profile:", profile_name)
- if password:
- print("\nPassword for this Wi-Fi profile is already saved.")
- else:
- print("\nPassword for this Wi-Fi profile is not saved.")
- password = input("Enter the Wi-Fi password: ")
- # Connect to the specified Wi-Fi profile
- subprocess.run(["netsh", "wlan", "connect", profile_name], check=True)
- print("\nConnected to:", profile_name)
- except subprocess.CalledProcessError as e:
- print("\nError:", e)
- def get_all_data():
- """
- Display all stored Wi-Fi passwords in clear text.
- """
- print("\n:: Stored Wi-Fi Passwords ::")
- wifi_profiles = list_wifi_profiles()
- for profile in wifi_profiles:
- password = get_wifi_password(profile)
- print(f"\nWi-Fi Profile:\t{profile}")
- if password:
- print(f"Password:\t{password}")
- else:
- print("Password:\t![Password not found]!")
- def main():
- while True:
- print("\nWLAN Netsh Options Menu:\n")
- print("1. Show All Available Networks + BBSID")
- print("2. Show Specified Wi-Fi Network Password")
- print("3. Connect To A WLAN Profile")
- print("4. Get All Stored WiFi Passwords")
- print("5. Exit")
- choice = input("\nEnter your choice (1-5): ")
- if choice == '1':
- show_available_networks()
- input("\nPress [ENTER] to continue...")
- elif choice == '2':
- profile_name = input("\nEnter profile name: ")
- show_wifi_password(profile_name)
- input("\nPress [ENTER] to continue...")
- elif choice == '3':
- # Display currently connected Wi-Fi network
- output = subprocess.check_output(["netsh", "wlan", "show", "interfaces"], text=True)
- connected_network = [line.split(":")[1].strip() for line in output.splitlines() if "SSID" in line]
- print("\nCurrently connected Wi-Fi network:", connected_network[0])
- # Prompt the user for the profile name to connect
- profile_name = input("\nConnect to Wi-Fi profile: ")
- # Call connect_to_profile function
- connect_to_profile(profile_name)
- input("\nPress [ENTER] to continue...")
- elif choice == '4':
- get_all_data()
- input("\nPress [ENTER] to continue...")
- elif choice == '5':
- print("\nExiting program...\tGoodBye!\n")
- break
- else:
- print("\nInvalid choice. Please enter a number between 1 and 5.\n")
- if __name__ == "__main__":
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement