-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathtest.py
More file actions
executable file
·62 lines (47 loc) · 1.6 KB
/
test.py
File metadata and controls
executable file
·62 lines (47 loc) · 1.6 KB
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
56
57
58
59
60
61
#!/usr/bin/python
import dbus
import sys
import os
#Types of NetworkManager devices
DEVICE_TYPE_UNKNOWN = 0
DEVICE_TYPE_802_3_ETHERNET = 1
DEVICE_TYPE_802_11_WIRELESS = 2
NM_DBUS_INTERFACE_DEVICES = "org.freedesktop.NetworkManager.Devices"
NM_DBUS_SERVICE = "org.freedesktop.NetworkManager"
NM_DBUS_INTERFACE = "org.freedesktop.NetworkManager"
NM_DBUS_PATH = "/org/freedesktop/NetworkManager"
class Device:
def GetDevices():
bus = dbus.SystemBus()
nm = bus.get_object(NM_DBUS_SERVICE, NM_DBUS_PATH)
devices = nm.getDevices(dbus_interface=NM_DBUS_INTERFACE_DEVICES)
return devices
GetDevices = staticmethod(GetDevices)
def GetWireless():
bus = dbus.SystemBus()
nm = bus.get_object(NM_DBUS_SERVICE, NM_DBUS_PATH)
devices = Device.GetDevices()
for device in devices:
dev = bus.get_object(NM_DBUS_SERVICE, device)
if dev.getType() == DEVICE_TYPE_802_11_WIRELESS:
return dev
GetWireless = staticmethod(GetWireless)
def setActive(device, network):
bus = dbus.SystemBus()
nm = bus.get_object(NM_DBUS_SERVICE, NM_DBUS_PATH)
nm.setActiveDevice(device, (bus.get_object(NM_DBUS_SERVICE, network)).getName())
class Network:
def __init__(self, url):
bus = dbus.SystemBus()
nm = bus.get_object(NM_DBUS_SERVICE, NM_DBUS_PATH)
net = bus.get_object(NM_DBUS_SERVICE, url)
self.url = network
self.name = net.getName()
#activenetwork = dev.getActiveNetwork()
self.encrypter = net.getEncrypted()
self.strength = int (net.getStrength())
dev = Device.GetWireless()
networks = dev.getNetworks()
for network in networks:
net = Network(network)
print net.name + ' -> ' + str(net.strength)