Skip to content

farman20ali/network_switcher

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

9 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Network Switcher Tray App

A simple, lightweight Linux system tray application to quickly switch between network modes (Wi-Fi, Wired, Both, Hotspot, or disable all) using NetworkManager (nmcli).

License Python Platform Version Status

πŸ“₯ Download

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.service

See Installation Guide for detailed instructions.

✨ Features

  • πŸ–₯️ 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 --version and --debug options
  • πŸ“ Comprehensive logging to ~/.config/network-switcher/

πŸ“‹ Requirements

System Requirements

  • Operating System: Linux with GUI (X11 or Wayland)
  • Python: 3.6 or higher
  • NetworkManager: nmcli command-line tool
  • systemd: For service management (optional)

Python Dependencies

  • pystray >= 0.19.4
  • Pillow >= 9.0.0

Note: The installation script automatically installs all missing dependencies!

οΏ½ Installation via .deb Package (Ubuntu/Debian)

The easiest way to install on Ubuntu/Debian systems is using the pre-built .deb package:

Step 1: Install the Package

sudo dpkg -i network-switcher_1.0.0-1_all.deb

Step 2: Start the Service

You have three options after installation:

Option 1: Start Immediately ⚑ (Fastest)

systemctl --user daemon-reload && systemctl --user enable --now network-switcher.service

The tray icon appears instantly!

Option 2: Auto-Enable on Next Login πŸ”„ (Easiest - No Commands Needed!)

Just logout and login again (or open a new terminal):

bash -l

The 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!

Option 3: Start Manually Later πŸ”§

systemctl --user start network-switcher.service

That's it! Choose the option that works best for you.

Verify Installation

Check if the service is running:

systemctl --user status network-switcher.service

Uninstalling the .deb Package

# Stop the service first
systemctl --user stop network-switcher.service
systemctl --user disable network-switcher.service

# Remove the package
sudo apt remove network-switcher

Building Your Own .deb Package

If you want to build the package from source:

./build-deb.sh

This will create network-switcher_1.0.0-1_all.deb in the current directory.

οΏ½πŸš€ Quick Installation

Automatic Installation (Recommended)

Simply run the installation script:

./install.sh

The script will:

  1. βœ… Check for all required system dependencies
  2. βœ… Verify Python version compatibility
  3. βœ… Install Python packages automatically
  4. βœ… Make the script executable
  5. βœ… Set up the systemd service
  6. βœ… Optionally enable and start the service

That's it! The Network Switcher will be installed and ready to use.

Manual Installation

If the automatic installation script doesn't work or you prefer manual installation, follow these steps:

Step 1: Install System Dependencies

Ubuntu/Debian:

sudo apt-get update
sudo apt-get install python3 python3-pip network-manager

Fedora/RHEL:

sudo dnf install python3 python3-pip NetworkManager

Arch Linux:

sudo pacman -S python python-pip networkmanager

Step 2: Install Python Dependencies

pip3 install --user -r requirements.txt

Or install manually:

pip3 install --user pystray Pillow

Step 3: Make the Script Executable

chmod +x network_switcher.py

Step 4: Create Network Icon (Optional)

If you don't have a network_icon.png file, generate one:

python3 create_icon.py

Or provide your own 64x64 PNG icon named network_icon.png.

πŸ“– Usage

Method 1: Using systemd Service (Recommended)

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.service

Method 2: Running Manually

If 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 &

Method 3: Manual systemd Service Setup

If the installation script didn't set up the service or you want to do it manually:

Method 3: Manual systemd Service Setup

If the installation script didn't set up the service or you want to do it manually:

  1. Create the systemd user service directory:

    mkdir -p ~/.config/systemd/user/
  2. Copy the service file to the systemd directory:

    cp network-switcher.service ~/.config/systemd/user/
  3. Important: Edit the service file to use absolute paths:

    nano ~/.config/systemd/user/network-switcher.service

    Replace the ExecStart line with the full path to your script:

    ExecStart=/full/path/to/network_switcher.py
    
  4. Reload systemd configuration:

    systemctl --user daemon-reload
  5. Enable the service to start on login:

    systemctl --user enable network-switcher.service
  6. Start the service:

    systemctl --user start network-switcher.service

πŸ—‘οΈ Uninstallation

Automatic Uninstallation (Recommended)

Simply run the uninstallation script:

./uninstall.sh

The 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)

Manual Uninstallation

If you need to uninstall manually:

  1. Stop and disable the service:

    systemctl --user stop network-switcher.service
    systemctl --user disable network-switcher.service
  2. Remove the service file:

    rm -f ~/.config/systemd/user/network-switcher.service
  3. Reload systemd:

    systemctl --user daemon-reload
  4. Optionally remove Python dependencies:

    pip3 uninstall pystray Pillow
  5. Remove the application directory:

    rm -rf /path/to/network_switcher

πŸŽ›οΈ Menu Options

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.

πŸ”§ Troubleshooting

The tray icon doesn't appear

  1. 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
  2. Check if the service is running:

    systemctl --user status network-switcher.service
  3. View logs for errors:

    journalctl --user -u network-switcher.service -n 50
  4. Try running manually to see errors:

    ./network_switcher.py

Missing dependencies error

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 Pillow

NetworkManager not found

The 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 Linux

Then enable and start NetworkManager:

sudo systemctl enable NetworkManager
sudo systemctl start NetworkManager

Permission denied errors

Make sure the script is executable:

chmod +x network_switcher.py

Hotspot not working

  1. Ensure you have a wired connection active
  2. Check that your Wi-Fi adapter supports AP mode:
    iw list | grep -A 10 "Supported interface modes"
  3. Verify NetworkManager has a hotspot connection configured

Icon not found

If you see a "network_icon.png not found" message:

  1. Generate a default icon:

    python3 create_icon.py
  2. Or provide your own 64x64 PNG icon named network_icon.png in the application directory

βš™οΈ Configuration

Customizing Connection Names

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"

Customizing Menu Icons

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
# ... etc

Changing Log Level

To see more detailed logs, edit the logging configuration in network_switcher.py:

logging.basicConfig(level=logging.DEBUG, stream=sys.stdout)

πŸ“ Project Structure

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

🀝 Contributing

Contributions are welcome! Here are some ways you can contribute:

  • πŸ› Report bugs and issues
  • πŸ’‘ Suggest new features
  • πŸ“– Improve documentation
  • πŸ”§ Submit pull requests

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ™ Acknowledgments

πŸ“ž Support

If you encounter any issues or have questions:

  1. Check the Troubleshooting section
  2. Review existing issues on GitHub
  3. 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

About

Instant network switching utility with WiFi, Ethernet, and interface controls.

Topics

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Packages

No packages published