{"id":18878284,"url":"https://github.com/uriel1998/networkcontrol-wicd-networkmanager","last_synced_at":"2026-04-13T21:31:32.488Z","repository":{"id":18604478,"uuid":"21809491","full_name":"uriel1998/networkcontrol-wicd-networkmanager","owner":"uriel1998","description":"A bash program to automagically run commands in userspace on network connection and disconnection.  Written to work with both WICD and Network-Manager","archived":false,"fork":false,"pushed_at":"2021-11-26T13:58:37.000Z","size":623,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-10-08T16:40:30.054Z","etag":null,"topics":["automation","bash","linux","networking","script"],"latest_commit_sha":null,"homepage":"http://uriel1998.github.io/networkcontrol-wicd-networkmanager/","language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/uriel1998.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-07-14T06:18:59.000Z","updated_at":"2022-04-17T09:04:00.000Z","dependencies_parsed_at":"2022-08-31T13:54:03.459Z","dependency_job_id":null,"html_url":"https://github.com/uriel1998/networkcontrol-wicd-networkmanager","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/uriel1998/networkcontrol-wicd-networkmanager","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uriel1998%2Fnetworkcontrol-wicd-networkmanager","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uriel1998%2Fnetworkcontrol-wicd-networkmanager/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uriel1998%2Fnetworkcontrol-wicd-networkmanager/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uriel1998%2Fnetworkcontrol-wicd-networkmanager/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/uriel1998","download_url":"https://codeload.github.com/uriel1998/networkcontrol-wicd-networkmanager/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uriel1998%2Fnetworkcontrol-wicd-networkmanager/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31771803,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-13T20:17:16.280Z","status":"ssl_error","status_checked_at":"2026-04-13T20:17:08.216Z","response_time":93,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["automation","bash","linux","networking","script"],"created_at":"2024-11-08T06:25:38.345Z","updated_at":"2026-04-13T21:31:32.470Z","avatar_url":"https://github.com/uriel1998.png","language":"Shell","funding_links":[],"categories":[],"sub_categories":[],"readme":"# network-middle-manager\n==================================\n\nA bash program to automagically run commands in userspace on network connection and disconnection.  Written to work with both WICD and Network-Manager\n\nThis originally started with [this](http://ideatrash.net/2013/10/getting-auto-login-window-on-public.html) and has grown into something quite a big larger, and then totally rewritten in 2021 to be a LOT simpler and more effective.\n\nI like this little octopus.  I imagine them being our manager. You cannot pronouce their name with a human tongue, sorry.\n\n![network middle manager logo](https://github.com/uriel1998/networkcontrol-wicd-networkmanager/blob/master/nmm-open-graph.png?raw=true \"logo\")\n\n\n## Contents\n 1. [About](#1-about)\n 2. [License](#2-license)\n 3. [Prerequisites](#3-prerequisites)\n 4. [Installation](#4-installation)\n 5. [Usage](#5-usage)\n 6. [TODO](#6-todo)\n\n***\n \n## 1. About\n\n`network-middle-manager`:\n* is focused on running tasks on network change\n* runs tasks *in userspace*, not as root\n* assumes *all* networks are **untrusted** unless explictly configured otherwise\n* works with both `network-manager` and `wicd`\n* uses a simple \"plugin\" style system for you to define what tasks to do where\n* uses YAD to provide an (optional) simple GUI to add tasks\n\nYou're traveling for the holidays.  You're at a coffeeshop.  And so on.  You connect \nto different networks, and want to spin up (or down) various processes depending \non what network you've connected to, and whether or not you trust them.\n\nThat's what `network-middle-manager` does.\n\nThis is written in the spirit of [Cuttlefish](https://www.debugpoint.com/2015/02/cuttlefish-an-event-driven-ubuntu-app-that-realises-reflexes-on-your-computer/) \nwas an ambitious (and needed!) automation driver for linux...which hasn't been \nupdated for a decade and doesn't currently run/compile on my system. \n\nI had written a very kludgy, very awkward script that kind of handled that, but \nit was so bad and flaky that even I didn't use it much.  So I've rewritten it \nentirely. It's in BASH so that it hopefully is more resistant to bitrot and is \neasily hackable by others.\n\n## 2. License\n\nThis project is licensed under the MIT license. For the full license, see `LICENSE`.\n\n## 3. Prerequisites\n\n### These may already be installed on your system.\n\n* `network-manager` or `wicd`\n* `curl`, `wget`, `awk`, `sed`, `sleep`, `grep`\n* `arp`, `netstat` (From `net-tools` in Debian)\n* `dig` (From `bind9-dnsutils` in Debian)\n* `iwgetid` (From `wireless-tools` in Debian)\n* `ip` (From `iproute2` in Debian)\n\n### Optional\n\n* [yad](https://smokey01.com/yad/) for GUI task setup, from `yad` in Debian\n\n## 4. Installation\n\n### For **both** Network Manager *and* WICD\n\n* Clone or download the repository and place it in a directory of your choice.  \n* Edit `02networkcontrol` (in the `emitters` directory) with the USERNAME to be used.  \n* Edit `02networkcontrol` (in the `emitters` directory) with the full path to `network-middle-manager.sh`.  \n* Put `02networkcontrol` in `/etc/NetworkManager/dispatcher.d/02networkcontrol`.  \n* `sudo chown root:root /etc/NetworkManager/dispatcher.d/02networkcontrol`\n* `sudo chmod +x /etc/NetworkManager/dispatcher.d/02networkcontrol`\n* Edit `network-middle-manager.ini` (see below).  \n* You can leave `network-middle-manager.ini` in the same directory or copy it to `$HOME/.config/network-middle-manager.ini`  \n* Set up your automatic processes.  \n\n### WICD only steps\n\n* Put `up.sh`  (in the `emitters` directory) in `/etc/wicd/scripts/preconnect`\n* Put `down.sh` (in the `emitters` directory) in `/etc/wicd/scripts/postconnect`\n* `sudo chmod +x /etc/wicd/scripts/preconnect/up.sh`\n* `sudo chmod +x /etc/wicd/scripts/preconnect/down.sh`\n\n### OPTIONAL\n\n* `50-disable-wireless-when-wired` : Does exactly what it says on the tin. If you \nwish to use this, copy it to `/etc/NetworkManager/dispatcher.d/` and then\n* `sudo chown root:root /etc/NetworkManager/dispatcher.d/50-disable-wireless-when-wired`\n* `sudo chmod +x /etc/NetworkManager/dispatcher.d/50-disable-wireless-when-wired`\n\n### network-middle-manager.ini\n\nThe format is simple; all networks are considered **UN**trusted except for the \nones you mark as trusted.  Therefore, the simplest setup is to leave everything \nunder \"Trusted\" blank.\n\nTrusted networks can be identified either by the SSID or the MAC address of \nthe gateway.  `wan_detect.sh` will give you that information for the **first** \nconnected network.  (Network Manager will connect to both a wired and wireless \nconnection at the same time unless you use the optional `50-disable-wireless-when-wired`.)  \nThe gateway MAC address should not change, even if you have a VPN running.  \n\n`latency` is used for a delay when you're *switching* networks - say from wireless \nto wired - so that the up commands do not conflict with the down commands. Default \nis 10 seconds.\n\n**IMPORTANT** Do not have any lines that START with `SSID=` or `MAC=` and nothing \nafter the equals sign for security reasons.  \n\n```\n[DEFAULT]\nlatency=10\n\n[Trusted]\nSSID=mySSIDisboring\nMAC=1a:2b:3c:4d:5e:6f\n```\n\n### Set up actions\n\nThis part requires `YAD`, or manually editing files. \n\n![setup screenshot](https://github.com/uriel1998/networkcontrol-wicd-networkmanager/blob/master/setup_screeshot.png?raw=true \"screenshot\")\n\nAll actions are designed to happen in *userspace*.  Run `setup-function.sh` in \nthe directory where you placed `network-middle-manager`.  Put the full path to \nthe command you wish to run, any arguments on the next line, and use the dropdown \nto determine whether the command should be run on a *trusted* network, an *untrusted* \nnetwork, or upon **any** network disconnect.\n\nFor example, I use [Private Internet Access](http://www.privateinternetaccess.com/pages/buy-a-vpn/1218buyavpn?invite=U2FsdGVkX1-SlyUtdYwtLcS0OJw83in87Dz9uyrKJUg%2CrHt7_wHO3z0c-uDZrCuQPIxALTo) (referral link).  \n\nI am going to only use it with untrusted networks, so my first setup task is: \n\n```\nTask: /usr/local/bin/piactl\nArgs: connect\nActionType: untrusted\n```\n\n![setup screenshot 1](https://github.com/uriel1998/networkcontrol-wicd-networkmanager/blob/master/setup_1.png?raw=true \"Setup 1\")\n\nMy second is \n\n```\nTask: /usr/local/bin/piactl\nArgs: disconnect\nActionType: disconnect\n```\n![setup screenshot 2](https://github.com/uriel1998/networkcontrol-wicd-networkmanager/blob/master/setup_2.png?raw=true \"Setup 2\")\n\nThis creates the plugins using the `template.txt` file and puts them in the right \ndirectory.  If you decide to manually create these, BASENAME is the basename of \nthe command, TASKNAME and TASKARGS are hopefully obvious, and they should be \ncopied into the appropriate plugin directory.\n\n### Multiple instances of the same command per network condition\n\nThis *will* fail if you have multiple commands with the same command for the \nsame network condition.  That is, you cannot have two \"trusted\" actions with the \ncommand `/bin/bash`.  \n\nIn that case, making (or using) a script that has the commands you want with the \nsame base command name.  It's all in your userspace, so hack away!\n\nLikewise, if you have a script that you need to run as another user (or root), \n(such as my [script for UFW](https://uriel1998.github.io/ufw-iptables-archer/)), \ncontain that inside another script as well.  \n\n### Note about PIA\n\nNote: PIA requires either the applet running or for you to have the daemon running \nby issuing the command `/usr/local/bin/piactl background enable` beforehand. \n\n## 5. Usage\n\nRestart network-manager to make sure that network-manager or wicd is aware of the new \nscripts. `network-middle-manager` will run the commands you told it to on network \nconnection or disconnection as the user you defined. \n\nYou may see `nmm_up.pid` and `nmm_down.pid` briefly appear in the application directory.\n\nYou *will* see `nmm_status` appear in the application directory. This is because \nof the way `network-manager` handles connection changes (e.g. when you plug an \nethernet cable into a system that's running on wireless).\n\n### Utilities\n\nThere are two additional utility scripts that are used with `network-middle-manager` that \ncan be used standalone as well:\n\n* `network_detect.sh`:  Checks if you're connected to a network with the defined \nproperties and both returns an exit code of 0 (success) or 99 (fail) and emits success|fail to STDOUT.\n\n`network_detect.sh --[match|unmatch] [MAC address|SSID|html file]`\n\nExample:  \n```\nnetwork_detect.sh --match \"http://10.10.1.5/default.html\"  \nnetwork_detect.sh --unmatch MySSID\n```\n    \n* `wan_detect.sh`: Gives you information quickly about active interfaces. It checks for \nthe first active interface, LAN ip4 address, and WAN ip4 address.  It also checks \nthe WAN address multiple ways if others fail.\n\n```\n -q : No headers on output.\n -s : Only the WAN ip, and exit code 99 if fail, 0 if success\n -v : Only the exit code 99 if fail, 0 if success\n```\nExample: `result=$(./wan_detect.sh -v; echo $?); if [ $result -eq 0 ];then ... ; fi`\n\n## 6. Todo\n\n * Have wan_detect be able to deal with multiple simultaneous connections.\n * the .keep files are literally so the empty directories exist in the repo.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Furiel1998%2Fnetworkcontrol-wicd-networkmanager","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Furiel1998%2Fnetworkcontrol-wicd-networkmanager","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Furiel1998%2Fnetworkcontrol-wicd-networkmanager/lists"}