
Product
Introducing Socket Fix for Safe, Automated Dependency Upgrades
Automatically fix and test dependency updates with socket fix—a new CLI tool that turns CVE alerts into safe, automated upgrades.
Network switching. Make sure you're connecting with the priority that you want.
Works on Linux (relies on wpa_supplicant)
pip install netswitch
Or you can use Docker instead:
# copy your wpa supplicant configs
cp -r ./aps /etc/wpa_supplicant/aps
docker run -d --privileged --network="host" \
-v /etc/wpa_supplicant:/etc/wpa_supplicant \
-e LIFELINE_SSID=mylifeline-2G \
--name netswitch beasteers/netswitch
where ./aps
is filled with a single wpa_supplicant network configuration and where the filename matches the SSID that's inside the file:
# all of the networks you want to be able to connect to
./aps/
networkA.conf
myspectrum-2G.conf
myspectrum-5G.conf
...
You can also use -v ./aps:/etc/wpa_supplicant/aps
instead of copying if you want the aps to be editable from their current location.
IMPORTANT: if you don't give it any aps to manage, it won't do anything.
import time
import netswitch
# tell netswitch where to get its AP list. see explanation below
netswitch.set_ap_path('path/to/aps')
# create a new wpa supplicant file
netswitch.generate_wpa_config('my-network-2G', 'wifipassword')
# create your network switching rules
witch = netswitch.NetSwitch([
{'interface': 'wlan*', 'ssids': 'lifeline'},
'eth*', # equivalent to {'interface': 'eth*'}
'ppp*',
{'interface': 'wlan*'}, # implied - 'ssids': '*'
])
# periodically check network
while True:
time.sleep(10)
connected = witch.check()
# or equivalently
witch.run(interval=10)
For example, assume your setup is:
Procedure - at any point in these steps, if we connect, we're finished:
For the collection of available APs and credentials that you can connect to, typically they are stored in a single /etc/wpa_supplicant/wpa_supplicant.conf
file and the wpa service will select the best one based on the priority specified. But this has issues and doesn't switch when one network is stronger than the other.
So, what's different:
So calling netswitch.sync_aps('path/to/aps')
tells netswitch
that each of your AP credentials are stored in individual files under 'path/to/aps'
.
You can also call netswitch.sync_aps('path/to/aps')
which will sync that directory with /etc/wpa_supplicant/aps/
and will operate out of there so that nothing will be touched in the original directory.
# run the wifi switcher with a lifeline ssid to look out for
python -m netswitch run --lifeline mylifelinenetwork-2G
# get ip addresses for available interfaces
python -m netswitch ip
python -m netswitch ip 'wlan*' 'eth*' # certain interfaces
# get available aps
python -m netswitch aps
python -m netswitch aps en0 # for mac
# get available interfaces
python -m netswitch iface
python -m netswitch iface '*tun*' 'eth*'
# restart interface
python -m netswitch restart wlan0
# list current wpa supplicant info
python -m netswitch wpa info
import netswitch
# get current wpa supplicant file
wpa = netswitch.Wpa()
# get
import netswitch.cell
assert isinstance(netswitch.cell.signal_strength(), float)
with netswitch.cell.Cell('/dev/ttyUSB2') as cell:
# read from stdind
cell.chat()
/etc/network/interfaces
????FAQs
wifi switching
We found that netswitch demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Automatically fix and test dependency updates with socket fix—a new CLI tool that turns CVE alerts into safe, automated upgrades.
Security News
CISA denies CVE funding issues amid backlash over a new CVE foundation formed by board members, raising concerns about transparency and program governance.
Product
We’re excited to announce a powerful new capability in Socket: historical data and enhanced analytics.