A simple, lightweight Linux system tray application to quickly switch between network modes (Wi-Fi, Wired, Both, Hotspot, or disable all) using NetworkManager (nmcli).
Latest Release: v1.0.0
# Download the .deb package
wget https://github.com/farman20ali/network_switcher/releases/download/v1.0.0/network-switcher_1.0.0-1_all.deb
# Install
sudo dpkg -i network-switcher_1.0.0-1_all.deb
# Start the service
systemctl --user daemon-reload && systemctl --user enable --now network-switcher.serviceSee Installation Guide for detailed instructions.
- π₯οΈ System tray icon with an intuitive menu for network switching
- πΆ Supports Wi-Fi, Wired, Both, Hotspot, and disabling all connections
- π Shows current connection status in the menu
- π Automatic connection detection and status updates
- π‘οΈ Graceful exit and tray icon removal on Ctrl+C or SIGTERM
- π¨ Uses Unicode icons for menu items (customizable)
- π Automatic dependency installation - No manual setup needed!
- βοΈ Runs as a systemd service (optional)
- π¦ Available as .deb packages for Debian/Ubuntu
- π§ Command-line interface with
--versionand--debugoptions - π Comprehensive logging to
~/.config/network-switcher/
- Operating System: Linux with GUI (X11 or Wayland)
- Python: 3.6 or higher
- NetworkManager:
nmclicommand-line tool - systemd: For service management (optional)
pystray>= 0.19.4Pillow>= 9.0.0
Note: The installation script automatically installs all missing dependencies!
The easiest way to install on Ubuntu/Debian systems is using the pre-built .deb package:
sudo dpkg -i network-switcher_1.0.0-1_all.debYou have three options after installation:
systemctl --user daemon-reload && systemctl --user enable --now network-switcher.serviceThe tray icon appears instantly!
Just logout and login again (or open a new terminal):
bash -lThe service will automatically enable and start on your next login!
How it works: The package installs a one-time setup script that automatically runs when you open a new login shell. It enables the service, starts it, shows a success message, and removes itself. Perfect for users who don't want to run manual commands!
systemctl --user start network-switcher.serviceThat's it! Choose the option that works best for you.
Check if the service is running:
systemctl --user status network-switcher.service# Stop the service first
systemctl --user stop network-switcher.service
systemctl --user disable network-switcher.service
# Remove the package
sudo apt remove network-switcherIf you want to build the package from source:
./build-deb.shThis will create network-switcher_1.0.0-1_all.deb in the current directory.
Simply run the installation script:
./install.shThe script will:
- β Check for all required system dependencies
- β Verify Python version compatibility
- β Install Python packages automatically
- β Make the script executable
- β Set up the systemd service
- β Optionally enable and start the service
That's it! The Network Switcher will be installed and ready to use.
If the automatic installation script doesn't work or you prefer manual installation, follow these steps:
Ubuntu/Debian:
sudo apt-get update
sudo apt-get install python3 python3-pip network-managerFedora/RHEL:
sudo dnf install python3 python3-pip NetworkManagerArch Linux:
sudo pacman -S python python-pip networkmanagerpip3 install --user -r requirements.txtOr install manually:
pip3 install --user pystray Pillowchmod +x network_switcher.pyIf you don't have a network_icon.png file, generate one:
python3 create_icon.pyOr provide your own 64x64 PNG icon named network_icon.png.
If you used the installation script and enabled the service, it's already running!
Control the service:
# Start the service
systemctl --user start network-switcher.service
# Stop the service
systemctl --user stop network-switcher.service
# Check service status
systemctl --user status network-switcher.service
# View logs
journalctl --user -u network-switcher.service -f
# Enable service to start on login
systemctl --user enable network-switcher.service
# Disable service
systemctl --user disable network-switcher.serviceIf you prefer to run the application without the systemd service:
# Run in foreground
./network_switcher.py
# Run in background
nohup ./network_switcher.py </dev/null >/dev/null 2>&1 &If the installation script didn't set up the service or you want to do it manually:
If the installation script didn't set up the service or you want to do it manually:
-
Create the systemd user service directory:
mkdir -p ~/.config/systemd/user/ -
Copy the service file to the systemd directory:
cp network-switcher.service ~/.config/systemd/user/ -
Important: Edit the service file to use absolute paths:
nano ~/.config/systemd/user/network-switcher.serviceReplace the
ExecStartline with the full path to your script:ExecStart=/full/path/to/network_switcher.py -
Reload systemd configuration:
systemctl --user daemon-reload
-
Enable the service to start on login:
systemctl --user enable network-switcher.service -
Start the service:
systemctl --user start network-switcher.service
Simply run the uninstallation script:
./uninstall.shThe script will:
- β Stop and disable the systemd service
- β Remove the service file
- β Optionally remove Python dependencies
- β Keep the application files (so you can reinstall if needed)
If you need to uninstall manually:
-
Stop and disable the service:
systemctl --user stop network-switcher.service systemctl --user disable network-switcher.service
-
Remove the service file:
rm -f ~/.config/systemd/user/network-switcher.service -
Reload systemd:
systemctl --user daemon-reload
-
Optionally remove Python dependencies:
pip3 uninstall pystray Pillow
-
Remove the application directory:
rm -rf /path/to/network_switcher
The system tray icon provides the following options:
- πΆ Switch to Wi-Fi: Enables Wi-Fi and disables wired connection
- π Switch to Wired: Enables wired connection and disables Wi-Fi
- π Enable Both Wi-Fi and Wired: Enables both connections simultaneously
- π‘ Turn On Hotspot: Enables hotspot mode (requires wired connection)
- β Stop All Connections: Disables all network connections
- Quit: Exits the application
The current connection status is displayed at the top of the menu.
-
Check if your desktop environment supports system tray icons:
- GNOME users may need the AppIndicator extension
- KDE Plasma, XFCE, and MATE usually support tray icons by default
-
Check if the service is running:
systemctl --user status network-switcher.service
-
View logs for errors:
journalctl --user -u network-switcher.service -n 50
-
Try running manually to see errors:
./network_switcher.py
If you see errors about missing dependencies, install them:
# Install system dependencies
sudo apt-get install python3 python3-pip network-manager # Ubuntu/Debian
sudo dnf install python3 python3-pip NetworkManager # Fedora/RHEL
sudo pacman -S python python-pip networkmanager # Arch Linux
# Install Python dependencies
pip3 install --user pystray PillowThe application requires NetworkManager and the nmcli command. Install it:
sudo apt-get install network-manager # Ubuntu/Debian
sudo dnf install NetworkManager # Fedora/RHEL
sudo pacman -S networkmanager # Arch LinuxThen enable and start NetworkManager:
sudo systemctl enable NetworkManager
sudo systemctl start NetworkManagerMake sure the script is executable:
chmod +x network_switcher.py- Ensure you have a wired connection active
- Check that your Wi-Fi adapter supports AP mode:
iw list | grep -A 10 "Supported interface modes"
- Verify NetworkManager has a hotspot connection configured
If you see a "network_icon.png not found" message:
-
Generate a default icon:
python3 create_icon.py
-
Or provide your own 64x64 PNG icon named
network_icon.pngin the application directory
The script automatically detects your Ethernet and Hotspot connection names. If detection fails or you want to use custom names, edit network_switcher.py:
# Near the top of the file
conn_name = "Your-Ethernet-Connection-Name"
hotspot_name = "Your-Hotspot-Name"To change the Unicode icons, edit the create_menu_items() function in network_switcher.py:
wifi_icon = "πΆ" # Change to your preferred icon
wired_icon = "π" # Change to your preferred icon
# ... etcTo see more detailed logs, edit the logging configuration in network_switcher.py:
logging.basicConfig(level=logging.DEBUG, stream=sys.stdout)network_switcher/
βββ network_switcher.py # Main application script
βββ network-switcher.service # systemd service file template
βββ network_switcher.desktop # Desktop entry file
βββ requirements.txt # Python dependencies
βββ install.sh # Installation script
βββ uninstall.sh # Uninstallation script
βββ create_icon.py # Icon generation script
βββ network_icon.png # Application icon (create or provide)
βββ README.md # This file
βββ LICENSE # MIT License
βββ .gitignore # Git ignore rules
Contributions are welcome! Here are some ways you can contribute:
- π Report bugs and issues
- π‘ Suggest new features
- π Improve documentation
- π§ Submit pull requests
This project is licensed under the MIT License - see the LICENSE file for details.
- Built with pystray for system tray functionality
- Uses Pillow for image processing
- Relies on NetworkManager for network management
If you encounter any issues or have questions:
- Check the Troubleshooting section
- Review existing issues on GitHub
- Create a new issue with:
- Your Linux distribution and version
- Python version (
python3 --version) - Error messages or logs
- Steps to reproduce the issue
Made with β€οΈ for the Linux community
Author: Your Name Here