-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwlan
executable file
·55 lines (45 loc) · 2.14 KB
/
wlan
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/usr/bin/python
import sys
import dbus, dbus.mainloop.glib
from gi.repository import GObject, GLib
GObject.threads_init()
dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
main_loop = GObject.MainLoop()
import argparse
parser = argparse.ArgumentParser(description='wpa_supplicant command line client')
parser.add_argument('-i', '--interface', metavar='IFACE', help='wifi interface, first if missing')
parser.add_argument('network', nargs='?', metavar='NET', help='network to enter or "any" to reset')
args = parser.parse_args()
if args.network is not None:
args.cmd = 'set'
else:
args.cmd = 'list'
if args.cmd == 'set':
if args.network == 'any':
args.network = None
else:
args.network = '"{}"'.format(args.network)
system_bus = dbus.SystemBus()
wpa_supplicant = dbus.Interface(system_bus.get_object('fi.w1.wpa_supplicant1', '/fi/w1/wpa_supplicant1'), 'fi.w1.wpa_supplicant1')
if args.interface == None:
iface_path = wpa_supplicant.Get('fi.w1.wpa_supplicant1', 'Interfaces', dbus_interface='org.freedesktop.DBus.Properties')[0]
else:
iface_path = wpa_supplicant.GetInterface(args.interface)
wifi_interface = dbus.Interface(system_bus.get_object('fi.w1.wpa_supplicant1', iface_path), 'fi.w1.wpa_supplicant1.Interface')
for netpath in wifi_interface.Get('fi.w1.wpa_supplicant1.Interface', 'Networks', dbus_interface='org.freedesktop.DBus.Properties'):
net = system_bus.get_object('fi.w1.wpa_supplicant1', netpath)
if args.cmd == 'set' and args.network is None:
net.Set('fi.w1.wpa_supplicant1.Network', 'Enabled', True, dbus_interface='org.freedesktop.DBus.Properties')
else:
props = net.Get('fi.w1.wpa_supplicant1.Network', 'Properties', dbus_interface='org.freedesktop.DBus.Properties')
if args.cmd == 'list':
print(props['ssid'][1:-1])
elif args.cmd == 'set' and props['ssid'] == args.network:
wifi_interface.SelectNetwork(netpath)
break
else:
if args.cmd == 'set' and args.network is not None:
print('No network with ssid {}'.format(args.network), file=sys.stderr)
sys.exit(1)
if args.cmd == 'set':
wifi_interface.Reassociate()