summaryrefslogtreecommitdiffstats
path: root/test/process-context-settings
blob: 67e679e7c530b924345e00d278cc1a2f95d3aa5f (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
49
50
51
52
53
54
55
56
57
58
#!/usr/bin/python

import os
import dbus

bus = dbus.SystemBus()

manager = dbus.Interface(bus.get_object('org.ofono', '/'),
						'org.ofono.Manager')

properties = manager.GetProperties()

for path in properties["Modems"]:
	modem = dbus.Interface(bus.get_object('org.ofono', path),
							'org.ofono.Modem')

	properties = modem.GetProperties()

	if "org.ofono.ConnectionManager" not in properties["Interfaces"]:
		continue

	connman = dbus.Interface(bus.get_object('org.ofono', path),
					'org.ofono.ConnectionManager')

	contexts = connman.GetContexts()

	for path, properties in contexts:
		if properties["Active"] == dbus.Boolean(0):
			continue

		print "Configuring %s" % (path)

		settings = properties["Settings"]

		interface = settings["Interface"]
		address = settings["Address"]
		try:
			gateway = settings["Gateway"]
		except:
			gateway = "0.0.0.0";

		if settings["Method"] == "dhcp":
			print "    Run DHCP on interface %s" % (interface)
		else:
			print "    IP address is %s" % (address)
			print "    Gateway is %s" % (gateway)

			cmd = "ifconfig " + interface + " " + address
			cmd += " netmask 255.255.255.255"
			os.system(cmd);

			for i in settings["DomainNameServers"]:
				print "    Nameserver is %s" % (i)

				cmd = "route add -host " + i
				cmd +=" dev " + interface
				os.system(cmd);
		print