SHARE
TWEET

check_ipv6_support.py

rfmonk Jun 29th, 2014 158 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/env python
  2. # check for IPv6 support
  3. # requires netifaces
  4.  
  5. import socket
  6. import argparse
  7. import netifaces as ni
  8.  
  9. def inspect_ipv6_support():
  10.         print "IPv6 support built into Python: %s" %socket.has_ipv6
  11.         ipv6_addr = {}
  12.         for interface in ni.interfaces():
  13.                 all_addresses = ni.ifaddresses(interface)
  14.                 print "Interface %s:" %interface
  15.                 for family,addrs in all_addresses.iteritems():
  16.                         fam_name = ni.address_families[family]
  17.                         print ' Address family: %s' % fam_name
  18.                         for  addr in addrs:
  19.                                 if fam_name == 'AF_INET6':
  20.                                         ipv6_addr[interface] = addr['addr']
  21.                                 print   '       Address         : %s' % addr['addr']
  22.                                 nmask = addr.get('netmask', None)
  23.                                 if nmask:
  24.                                         print ' Netmask         : %s' % nmask
  25.                                 bcast = addr.get('broadcast', None)
  26.                                 if bcast:
  27.                                         print ' Broadcast       : %s' % bcast
  28.  
  29.         if ipv6_addr:
  30.                 print "Found IPv6 address: %s" %ipv6_addr
  31.         else:
  32.                 print "No IPv6 interface found!"
  33.  
  34. if __name__ == '__main__':
  35.         inspect_ipv6_support()
RAW Paste Data
Top