Created
August 21, 2016 22:11
-
-
Save hawkins/523adbc99fab1e76600f31060ba87d5c to your computer and use it in GitHub Desktop.
Python CLI for managing WiFi connections with NMCLI
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
import os | |
import click | |
@click.group() | |
@click.pass_context | |
def cli(ctx): | |
"""The CLI for PyFi""" | |
pass | |
@cli.command() | |
@click.argument('ssid') | |
@click.argument('pw') | |
@click.option('--iface', default='wlan0', help='Network interface to use.') | |
def connect(ssid, pw, iface): | |
"""Connect to a given network""" | |
click.echo('Connecting to %s' % ssid) | |
os.system('nmcli d wifi connect "%s" password %s iface %s' % (ssid, pw, iface)) | |
@cli.command() | |
@click.argument('iface') | |
def disconnect(iface): | |
"""Disconnect from a given interface""" | |
click.echo('Disconnecting interface %s' % iface) | |
os.system('nmcli d disconnect iface %s' % iface) | |
if __name__ == "__main__": | |
cli() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment