ofono/test/process-context-settings

61 lines
1.4 KiB
Plaintext
Raw Normal View History

#!/usr/bin/python3
import os
import sys
import dbus
bus = dbus.SystemBus()
manager = dbus.Interface(bus.get_object('org.ofono', '/'),
'org.ofono.Manager')
2010-09-09 19:37:37 +00:00
modems = manager.GetModems()
2010-09-09 19:37:37 +00:00
for path, properties in modems:
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), file=sys.stderr)
settings = properties["Settings"]
interface = settings["Interface"]
if settings["Method"] == "dhcp":
print(" Run DHCP on interface %s" % (interface),
file=sys.stderr)
else:
2017-11-14 02:45:04 +00:00
address = settings["Address"]
try:
gateway = settings["Gateway"]
except:
gateway = "0.0.0.0";
print(" Interface is %s" % (interface),
file=sys.stderr)
print(" IP address is %s" % (address),
file=sys.stderr)
print(" Gateway is %s" % (gateway),
file=sys.stderr)
cmd = "ip address add dev " + interface + " " + address
cmd += "/32"
os.system(cmd);
for i in settings["DomainNameServers"]:
print(" Nameserver is %s" % (i),
file=sys.stderr)
cmd = "ip route add " + i
cmd +=" dev " + interface
os.system(cmd);
print('', file=sys.stderr)