summaryrefslogtreecommitdiff
path: root/test/set-address
blob: 92016784806f384144823356243954650cedf969 (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
#!/usr/bin/python

import sys
import dbus

if (len(sys.argv) < 3):
	print "Usage: %s <address> <netmask | prefix length> <gateway> [version]" % (sys.argv[0])
	sys.exit(1)

bus = dbus.SystemBus()

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

properties = manager.GetProperties()

for path in properties["Services"]:
	service = dbus.Interface(bus.get_object('net.connman', path),
						'net.connman.Service')

	properties = service.GetProperties()



	if (len(sys.argv) == 5 and sys.argv[4] == "ipv6"):
		ipv = 6
	else:
		ipv = 4

	print "Setting IPv%d address %s for %s" % (ipv, sys.argv[1], path)

	if (ipv == 4):
		service.SetProperty("IPv4.Configuration",
					{ "Method": "manual",
						"Address": sys.argv[1],
						"Netmask": sys.argv[2],
							"Gateway": sys.argv[3]})
	else:
		service.SetProperty("IPv6.Configuration",
					{ "Method": "manual",
						"Address": sys.argv[1],
						"PrefixLength": sys.argv[2],
							"Gateway": sys.argv[3]})

	print