本文整理汇总了Python中netifaces.address_families方法的典型用法代码示例。如果您正苦于以下问题:Python netifaces.address_families方法的具体用法?Python netifaces.address_families怎么用?Python netifaces.address_families使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类netifaces
的用法示例。
在下文中一共展示了netifaces.address_families方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: inspect_ipv6_support
# 需要导入模块: import netifaces [as 别名]
# 或者: from netifaces import address_families [as 别名]
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!")
开发者ID:PacktPublishing,项目名称:Learning-Python-Networking-Second-Edition,代码行数:25,代码来源:check_ipv6_support.py
示例2: extract_ipv6_info
# 需要导入模块: import netifaces [as 别名]
# 或者: from netifaces import address_families [as 别名]
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")
开发者ID:PacktPublishing,项目名称:Learning-Python-Networking-Second-Edition,代码行数:24,代码来源:extract_ipv6_info.py
示例3: inspect_ipv6_support
# 需要导入模块: import netifaces [as 别名]
# 或者: from netifaces import address_families [as 别名]
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!")
开发者ID:PacktPublishing,项目名称:Python-Network-Programming-Cookbook-Second-Edition,代码行数:27,代码来源:3_10_check_ipv6_support.py
示例4: extract_ipv6_info
# 需要导入模块: import netifaces [as 别名]
# 或者: from netifaces import address_families [as 别名]
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")
开发者ID:PacktPublishing,项目名称:Python-Network-Programming-Cookbook-Second-Edition,代码行数:25,代码来源:3_11_extract_ipv6_prefix.py
示例5: dump_addresses
# 需要导入模块: import netifaces [as 别名]
# 或者: from netifaces import address_families [as 别名]
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)
示例6: run
# 需要导入模块: import netifaces [as 别名]
# 或者: from netifaces import address_families [as 别名]
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