summaryrefslogtreecommitdiff
path: root/test/vpn-get
blob: c9c5a7002ba3b73bbfb01e7b7fc3d4ea8c987a3a (plain)
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
#!/usr/bin/python

import dbus

def extract_values(values):
	val = "{"
	for key in list(values.keys()):
		val += " " + key + "="
		if key in ["Servers", "Excludes"]:
			val += extract_list(values[key])
		else:
			val += str(values[key])
	val += " }"
	return val

def extract_list(list):
	val = "["
	for i in list:
		if type(i).__name__ == 'Dictionary':
			val += extract_values(i)
		elif type(i).__name__ == 'Struct':
			val += extract_list(i)
		else:
			val += " " + str(i)
	val += "]"
	return val

bus = dbus.SystemBus()

manager = dbus.Interface(bus.get_object('net.connman.vpn', '/'),
					'net.connman.vpn.Manager')

for entry in manager.GetConnections():
	path = entry[0]
	properties = entry[1]

	print("[ %s ]" % (path))

	for key in list(properties.keys()):
		if key in ["IPv4", "IPv6" ]:
			val = extract_values(properties[key])
		elif key in ["Nameservers","ServerRoutes","UserRoutes"]:
			val = extract_list(properties[key])
		else:
			val = str(properties[key])
		print("    %s = %s" % (key, val))

	print()