summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorJiří Klimeš <jklimes@redhat.com>2014-01-22 15:40:22 +0100
committerJiří Klimeš <jklimes@redhat.com>2014-01-23 12:56:45 +0100
commit85272df6eb89682a3d13022281085b97527955e1 (patch)
treef458000983ec9c2e0c39486710ed95b2fa0c8094 /examples
parent8ee4f58e9ee67df2ef761a691dec55c6008ad4ff (diff)
downloadNetworkManager-85272df6eb89682a3d13022281085b97527955e1.tar.gz
examples: update get_ips.py python example for DNS information
Diffstat (limited to 'examples')
-rwxr-xr-xexamples/python/gi/get_ips.py44
1 files changed, 40 insertions, 4 deletions
diff --git a/examples/python/gi/get_ips.py b/examples/python/gi/get_ips.py
index b1e59e2215..6903b6de20 100755
--- a/examples/python/gi/get_ips.py
+++ b/examples/python/gi/get_ips.py
@@ -24,8 +24,8 @@ import sys, socket, struct
from gi.repository import GLib, NetworkManager, NMClient
#
-# This example shows how to get get addresses and routes from NMIP4Config and NMIP6Config
-# (got out of NMDevice)
+# This example shows how to get addresses, routes and DNS information
+# from NMIP4Config and NMIP6Config (got out of NMDevice)
#
def show_addresses(self, family):
@@ -59,7 +59,6 @@ def show_addresses(self, family):
socket.inet_ntop(family, gateway_struct))
-
def show_routes(self, family):
if (family == socket.AF_INET):
ip_cfg = self.get_ip4_config()
@@ -70,7 +69,7 @@ def show_routes(self, family):
print("None")
return
- nm_routes = ip_cfg.get_routes()
+ nm_routes = ip_cfg.get_routes()
if len(nm_routes) == 0:
print("None")
return
@@ -93,6 +92,33 @@ def show_routes(self, family):
metric)
+def show_dns(self, family):
+ if (family == socket.AF_INET):
+ ip_cfg = self.get_ip4_config()
+ else:
+ ip_cfg = self.get_ip6_config()
+
+ if ip_cfg is None:
+ print("None")
+ return
+
+ if (family == socket.AF_INET):
+ print ("Domains: %s") % (ip_cfg.get_domains())
+ print ("Searches: %s") % (ip_cfg.get_searches())
+ print("Nameservers:")
+ nameservers = ip_cfg.get_nameservers()
+ for dns in nameservers:
+ print socket.inet_ntop(family, struct.pack("=I", dns))
+ else:
+ print ("Domains: %s") % (ip_cfg.get_domains())
+ print ("Searches: %s") % (ip_cfg.get_searches())
+ print("Nameservers:")
+ num = ip_cfg.get_num_nameservers()
+ for i in range(0,num):
+ dns = ip_cfg.get_nameserver(i)
+ print socket.inet_ntop(family, dns)
+
+
if __name__ == "__main__":
if len(sys.argv) != 2:
sys.exit('Usage: %s <interface>' % sys.argv[0])
@@ -125,3 +151,13 @@ if __name__ == "__main__":
show_routes(dev, socket.AF_INET6)
print
+ print "IPv4 DNS:"
+ print("------------")
+ show_dns(dev, socket.AF_INET)
+ print
+
+ print "IPv6 DNS:"
+ print("------------")
+ show_dns(dev, socket.AF_INET6)
+ print
+