Python netifaces.address_families() Examples

The following are 8 code examples of netifaces.address_families(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module netifaces , or try the search function .
Example #1
Source File: check_ipv6_support.py    From Learning-Python-Networking-Second-Edition with MIT License 6 votes vote down vote up
def inspect_ipv6_support():
    print ("IPV6 support built into Python: %s" %socket.has_ipv6)
    ipv6_addresses = {}
    for interface in netifaces.interfaces():
        all_addresses = netifaces.ifaddresses(interface)
        print ("Interface %s:" %interface)
        for family,addrs in all_addresses.items():
            fam_name = netifaces.address_families[family]
            print ('  Address family: %s' % fam_name)
            for addr in addrs:
                if fam_name == 'AF_INET6':
                    ipv6_addresses[interface] = addr['addr']
                print ('    Address  : %s' % addr['addr'])
                nmask = addr.get('netmask', None)
                if nmask:
                    print ('    Netmask  : %s' % nmask)
                bcast = addr.get('broadcast', None)
                if bcast:
                    print ('    Broadcast: %s' % bcast)
    if ipv6_addresses:
        print ("Found IPv6 address: %s" %ipv6_addresses)
    else:
        print ("No IPv6 interface found!") 
Example #2
Source File: extract_ipv6_info.py    From Learning-Python-Networking-Second-Edition with MIT License 6 votes vote down vote up
def extract_ipv6_info():
    print ("IPv6 support built into Python: %s" %socket.has_ipv6)
    for interface in netifaces.interfaces():
        all_addresses = netifaces.ifaddresses(interface)
        print ("Interface %s:" %interface)
        for family,addrs in all_addresses.items():
            fam_name = netifaces.address_families[family]

            for addr in addrs:
                if fam_name == 'AF_INET6':
                    addr = addr['addr']
                    has_eth_string = addr.split("%eth")
                    if has_eth_string:
                        addr = addr.split("%eth")[0]
                    try:
                        print ("    IP Address: %s" %netaddr.IPNetwork(addr))
                        print ("    IP Version: %s" %netaddr.IPNetwork(addr).version)
                        print ("    IP Prefix length: %s" %netaddr.IPNetwork(addr).prefixlen)
                        print ("    Network: %s" %netaddr.IPNetwork(addr).network)
                        print ("    Broadcast: %s" %netaddr.IPNetwork(addr).broadcast)
                    except Exception as e:
                        print ("Skip Non-IPv6 Interface") 
Example #3
Source File: 3_10_check_ipv6_support.py    From Python-Network-Programming-Cookbook-Second-Edition with MIT License 6 votes vote down vote up
def inspect_ipv6_support():
    """ Find the ipv6 address"""
    print ("IPV6 support built into Python: %s" %socket.has_ipv6)
    ipv6_addr = {}
    for interface in ni.interfaces():
        all_addresses = ni.ifaddresses(interface)
        print ("Interface %s:" %interface)

        for family,addrs in all_addresses.items():
            fam_name = ni.address_families[family]
            print ('  Address family: %s' % fam_name)
            for addr in addrs:
                if fam_name == 'AF_INET6':
                    ipv6_addr[interface] = addr['addr']
                print ('    Address  : %s' % addr['addr'])
                nmask = addr.get('netmask', None)
                if nmask:
                    print ('    Netmask  : %s' % nmask)
                bcast = addr.get('broadcast', None)
                if bcast:
                    print ('    Broadcast: %s' % bcast)
    if ipv6_addr:
        print ("Found IPv6 address: %s" %ipv6_addr)
    else:
        print ("No IPv6 interface found!") 
Example #4
Source File: 3_11_extract_ipv6_prefix.py    From Python-Network-Programming-Cookbook-Second-Edition with MIT License 6 votes vote down vote up
def extract_ipv6_info():
    """ Extracts IPv6 information"""
    print ("IPv6 support built into Python: %s" %socket.has_ipv6)
    for interface in ni.interfaces():
        all_addresses = ni.ifaddresses(interface)
        print ("Interface %s:" %interface)
        for family,addrs in all_addresses.items():
            fam_name = ni.address_families[family]

            for addr in addrs:
                if fam_name == 'AF_INET6':
                    addr = addr['addr']
                    has_eth_string = addr.split("%eth")
                    if has_eth_string:
                        addr = addr.split("%eth")[0]
                    try:
                        print ("    IP Address: %s" %na.IPNetwork(addr))
                        print ("    IP Version: %s" %na.IPNetwork(addr).version)
                        print ("    IP Prefix length: %s" %na.IPNetwork(addr).prefixlen)
                        print ("    Network: %s" %na.IPNetwork(addr).network)
                        print ("    Broadcast: %s" %na.IPNetwork(addr).broadcast)
                    except Exception as e:
                        print ("Skip Non-IPv6 Interface") 
Example #5
Source File: 13_10_check_ipv6_support.py    From Python-Network-Programming with MIT License 6 votes vote down vote up
def inspect_ipv6_support():
    """ Find the ipv6 address"""
    print ("IPV6 support built into Python: %s" %socket.has_ipv6)
    ipv6_addr = {}
    for interface in ni.interfaces():
        all_addresses = ni.ifaddresses(interface)
        print ("Interface %s:" %interface)

        for family,addrs in all_addresses.items():
            fam_name = ni.address_families[family]
            print ('  Address family: %s' % fam_name)
            for addr in addrs:
                if fam_name == 'AF_INET6':
                    ipv6_addr[interface] = addr['addr']
                print ('    Address  : %s' % addr['addr'])
                nmask = addr.get('netmask', None)
                if nmask:
                    print ('    Netmask  : %s' % nmask)
                bcast = addr.get('broadcast', None)
                if bcast:
                    print ('    Broadcast: %s' % bcast)
    if ipv6_addr:
        print ("Found IPv6 address: %s" %ipv6_addr)
    else:
        print ("No IPv6 interface found!") 
Example #6
Source File: 13_11_extract_ipv6_prefix.py    From Python-Network-Programming with MIT License 6 votes vote down vote up
def extract_ipv6_info():
    """ Extracts IPv6 information"""
    print ("IPv6 support built into Python: %s" %socket.has_ipv6)
    for interface in ni.interfaces():
        all_addresses = ni.ifaddresses(interface)
        print ("Interface %s:" %interface)
        for family,addrs in all_addresses.items():
            fam_name = ni.address_families[family]

            for addr in addrs:
                if fam_name == 'AF_INET6':
                    addr = addr['addr']
                    has_eth_string = addr.split("%eth")
                    if has_eth_string:
                        addr = addr.split("%eth")[0]
                    try:
                        print ("    IP Address: %s" %na.IPNetwork(addr))
                        print ("    IP Version: %s" %na.IPNetwork(addr).version)
                        print ("    IP Prefix length: %s" %na.IPNetwork(addr).prefixlen)
                        print ("    Network: %s" %na.IPNetwork(addr).network)
                        print ("    Broadcast: %s" %na.IPNetwork(addr).broadcast)
                    except Exception as e:
                        print ("Skip Non-IPv6 Interface") 
Example #7
Source File: find-best-address.py    From networkzero with MIT License 5 votes vote down vote up
def dump_addresses():
    for interface in netifaces.interfaces():
        print(interface)
        ifaddresses = netifaces.ifaddresses(interface)
        for family in ifaddresses:
            print("  ", netifaces.address_families[family])
            address_info = ifaddresses[family]
            for info in address_info:
                print("    ", info) 
Example #8
Source File: network_enumeration_interfaces.py    From locasploit with GNU General Public License v2.0 5 votes vote down vote up
def run(self):
        silent = positive(self.parameters['SILENT'].value)
        
        import netifaces as n
        ifs = n.interfaces()
        result = {}
        for iface in  ifs:
            afs = {}
            for ad in n.ifaddresses(iface):
                afs[n.address_families[ad]] = n.ifaddresses(iface)[ad]
            result[iface] = afs
        
        #output
        if not silent:
            for interface in result:            
                log.ok('%s:' % interface)
                for afamily in result[interface]:
                    log.ok('    %s:' %afamily)
                    for addressid in range(0, len(result[interface][afamily])):
                        log.ok('        address %d:' % addressid)
                        address = result[interface][afamily][addressid]
                        for key in address:
                            log.ok('            %s = %s' % (key, address[key]))

        #lib.kb.add('NETWORK INTERFACES', result)
        for x in result:
            lib.kb.add('NETWORK INTERFACES %s' % (x), result[x])
        # # # # # # # #
        return None