about summary refs log tree commit diff
path: root/examples/python/gi/get_ips.py
diff options
context:
space:
mode:
authorMichael Biebl <biebl@debian.org>2020-06-28 18:58:14 +0200
committerMichael Biebl <biebl@debian.org>2020-06-28 18:58:14 +0200
commita54ac63bbf9b2c71026ac9028a8ffaf186cf3c82 (patch)
tree6a32883bd916c4096357b35298beff6db8bcd0b5 /examples/python/gi/get_ips.py
parent45e8e1149027529194982212c804c0468aa01d98 (diff)
New upstream version 1.25.90 upstream/1.25.90
Diffstat (limited to 'examples/python/gi/get_ips.py')
-rwxr-xr-xexamples/python/gi/get_ips.py45
1 files changed, 24 insertions, 21 deletions
diff --git a/examples/python/gi/get_ips.py b/examples/python/gi/get_ips.py
index 13b0a8b6..07d6f0cc 100755
--- a/examples/python/gi/get_ips.py
+++ b/examples/python/gi/get_ips.py
@@ -6,19 +6,21 @@
 
 import sys, socket
 import gi
-gi.require_version('NM', '1.0')
-from gi.repository import GLib, NM
+
+gi.require_version("NM", "1.0")
+from gi.repository import NM
 
 #
 #  This example shows how to get addresses, routes and DNS information
 #  from NMIP4Config and NMIP6Config (got out of NMDevice)
 #
 
+
 def show_addresses(dev, family):
-    if (family == socket.AF_INET):
-       ip_cfg = dev.get_ip4_config()
+    if family == socket.AF_INET:
+        ip_cfg = dev.get_ip4_config()
     else:
-       ip_cfg = dev.get_ip6_config()
+        ip_cfg = dev.get_ip6_config()
 
     if ip_cfg is None:
         print("None")
@@ -35,8 +37,9 @@ def show_addresses(dev, family):
 
         print("%s/%d") % (addr, prefix)
 
+
 def show_gateway(dev, family):
-    if (family == socket.AF_INET):
+    if family == socket.AF_INET:
         ip_cfg = dev.get_ip4_config()
     else:
         ip_cfg = dev.get_ip6_config()
@@ -45,16 +48,17 @@ def show_gateway(dev, family):
         gw = "None"
     else:
         gw = ip_cfg.get_gateway()
-        if gw == '':
+        if gw == "":
             gw = "None"
 
     print(gw)
 
+
 def show_routes(dev, family):
-    if (family == socket.AF_INET):
-       ip_cfg = dev.get_ip4_config()
+    if family == socket.AF_INET:
+        ip_cfg = dev.get_ip4_config()
     else:
-       ip_cfg = dev.get_ip6_config()
+        ip_cfg = dev.get_ip6_config()
 
     if ip_cfg is None:
         print("None")
@@ -75,31 +79,31 @@ def show_routes(dev, family):
 
 
 def show_dns(dev, family):
-    if (family == socket.AF_INET):
-       ip_cfg = dev.get_ip4_config()
+    if family == socket.AF_INET:
+        ip_cfg = dev.get_ip4_config()
     else:
-       ip_cfg = dev.get_ip6_config()
+        ip_cfg = dev.get_ip6_config()
 
     if ip_cfg is None:
         print("None")
         return
 
-    print ("Nameservers: %s") % (ip_cfg.get_nameservers())
-    print ("Domains: %s") % (ip_cfg.get_domains())
-    print ("Searches: %s") % (ip_cfg.get_searches())
-    if (family == socket.AF_INET):
-        print ("WINS: %s") % (ip_cfg.get_wins_servers())
+    print("Nameservers: %s") % (ip_cfg.get_nameservers())
+    print("Domains: %s") % (ip_cfg.get_domains())
+    print("Searches: %s") % (ip_cfg.get_searches())
+    if family == socket.AF_INET:
+        print("WINS: %s") % (ip_cfg.get_wins_servers())
 
 
 if __name__ == "__main__":
     if len(sys.argv) != 2:
-        sys.exit('Usage: %s <interface>' % sys.argv[0])
+        sys.exit("Usage: %s <interface>" % sys.argv[0])
     dev_iface = sys.argv[1]
 
     c = NM.Client.new(None)
     dev = c.get_device_by_iface(dev_iface)
     if dev is None:
-        sys.exit('Device \'%s\' not found' % dev_iface)
+        sys.exit("Device '%s' not found" % dev_iface)
     print("Device: %s - %s" % (dev_iface, dev.get_device_type().value_name))
     print("---------------------------------------")
 
@@ -142,4 +146,3 @@ if __name__ == "__main__":
     print("------------")
     show_dns(dev, socket.AF_INET6)
     print
-