Add D-Bus interface for configuring IP addresses
[platform/upstream/connman.git] / test / set-address
1 #!/usr/bin/python
2
3 import sys
4 import dbus
5
6 if (len(sys.argv) < 2):
7         print "Usage: %s <address> [netmask]" % (sys.argv[0])
8         sys.exit(1)
9
10 bus = dbus.SystemBus()
11
12 manager = dbus.Interface(bus.get_object('org.moblin.connman', "/"),
13                                         'org.moblin.connman.Manager')
14
15 properties = manager.GetProperties()
16
17 for path in properties["Services"]:
18         service = dbus.Interface(bus.get_object('org.moblin.connman', path),
19                                                 'org.moblin.connman.Service')
20
21         properties = service.GetProperties()
22
23         if properties["State"] != "ready":
24                 continue
25
26         print "Setting address %s for %s" % (sys.argv[1], path)
27
28         if len(sys.argv) > 2:
29                 service.SetProperty("IPv4.Configuration",
30                         { "Method": "manual", "Address": sys.argv[1],
31                                                 "Netmask": sys.argv[2] })
32         else:
33                 service.SetProperty("IPv4.Configuration",
34                         { "Method": "manual", "Address": sys.argv[1] })
35
36         print