netaddr Network Address Tool python

Print ( "========== ==========. 1") 
from the netaddr Import IPNetwork 

# IPNetwork ( '192.168.7.80/30'), IPNetwork ( '192.168.7.84/30 '), IPNetwork (' 192.168.7.88/30 '), IPNetwork (' 192.168.7.92/30 ') 
ip_str = "192.168.7.83/28" 
# ip_str = "192.168.7.92/30" 
# ip_str = "192.168.1.130 / 32 " 
# ip_str =" 192.168.34.92/255.255.255.248 " 
Print (ip_str) 
IP = IPNetwork (ip_str) 
Print (IP) 

# Subnet Mask 
Print (ip.netmask) 
# broadcast address 
Print (ip.broadcast) 
# network address 
Print (ip.network) 
# negated mask 
Print (ip.hostmask) 
# same segment ip Total 
print (ip.size) 
mask length to modify the address # 28 
ip.prefixlen = 28
print(ip)

The same network segment # ip, and then into several subnet mask length of 30 
new_ips_list = [X for X in ip.subnet (30)] 
Print (new_ips_list) 

# # obtain addresses of all hosts on a network segment 
ip in IPNetwork for (ip_str) .iter_hosts (): 
    Print (ip) 

Print ( "========== ========== 2") 
# IPAddress usage 
from netaddr import IPAddress 

# determined public network address, private property 
Print (the IPAddress ( "100.64.0.1"). is_private ()) 
Print (the IPAddress ( "114.114.114.114"). is_private ()) 

Print ( "======= === ========== 3 ") 
range # define any of IP addresses 
from the netaddr Import the IPRange 

IP_RANGE the IPRange = (" 192.168.1.10 "," 192.168.1.130 ") 
# ip address this paragraph polymerizing the address 
Print (ip_range.cidrs ()) 

Print ( "========== ==========. 4") 
# ip plurality of dispersion polymerization then
from netaddr import cidr_merge

ip_list = []
ip_list.append(IPNetwork("192.168.1.0/25"))
ip_list.append(IPNetwork("192.168.1.128/25"))
ip_list.append(IPNetwork("192.168.0.0/24"))
ip_list.append(IPNetwork("192.168.3.0/26"))
ip_list.append(IPNetwork("192.168.3.64/26"))
print(cidr_merge(ip_list))

print("==========5==========")
# 处理MAC地址
from netaddr import EUI, mac_unix, mac_cisco, mac_bare

# mac = EUI("98:5a:eb:9f:35:f8")
mac = EUI("98-5A-EB-9F-35-F8")
print(mac)

# mac显示风格1
mac.dialect = mac_unix
print(mac)
# mac显示风格2
mac.= mac_cisco dialect 
# 3 display style MAC
Print (MAC)
= mac_bare mac.dialect 
Print (MAC) 

# MAC address manufacturer information 
print (mac.info)

 Output:

Print ( "========== ==========. 1") 
from the netaddr Import IPNetwork 

# IPNetwork ( '192.168.7.80/30'), IPNetwork ( '192.168.7.84/30 '), IPNetwork (' 192.168.7.88/30 '), IPNetwork (' 192.168.7.92/30 ') 
ip_str = "192.168.7.83/28" 
# ip_str = "192.168.7.92/30" 
# ip_str = "192.168.1.130 / 32 " 
# ip_str =" 192.168.34.92/255.255.255.248 " 
Print (ip_str) 
IP = IPNetwork (ip_str) 
Print (IP) 

# Subnet Mask 
Print (ip.netmask) 
# broadcast address 
Print (ip.broadcast) 
# network address 
Print (ip.network) 
# negated mask 
Print (ip.hostmask) 
# same segment ip Total 
print (ip.size) 
mask length to modify the address # 28 
ip.prefixlen = 28
print(ip)

The same network segment # ip, and then into several subnet mask length of 30 
new_ips_list = [X for X in ip.subnet (30)] 
Print (new_ips_list) 

# # obtain addresses of all hosts on a network segment 
ip in IPNetwork for (ip_str) .iter_hosts (): 
    Print (ip) 

Print ( "========== ========== 2") 
# IPAddress usage 
from netaddr import IPAddress 

# determined public network address, private property 
Print (the IPAddress ( "100.64.0.1"). is_private ()) 
Print (the IPAddress ( "114.114.114.114"). is_private ()) 

Print ( "======= === ========== 3 ") 
range # define any of IP addresses 
from the netaddr Import the IPRange 

IP_RANGE the IPRange = (" 192.168.1.10 "," 192.168.1.130 ") 
# ip address this paragraph polymerizing the address 
Print (ip_range.cidrs ()) 

Print ( "========== ==========. 4") 
# ip plurality of dispersion polymerization then
from netaddr import cidr_merge

ip_list = []
ip_list.append(IPNetwork("192.168.1.0/25"))
ip_list.append(IPNetwork("192.168.1.128/25"))
ip_list.append(IPNetwork("192.168.0.0/24"))
ip_list.append(IPNetwork("192.168.3.0/26"))
ip_list.append(IPNetwork("192.168.3.64/26"))
print(cidr_merge(ip_list))

print("==========5==========")
# 处理MAC地址
from netaddr import EUI, mac_unix, mac_cisco, mac_bare

# mac = EUI("98:5a:eb:9f:35:f8")
mac = EUI("98-5A-EB-9F-35-F8")
print(mac)

# mac显示风格1
mac.dialect = mac_unix
print(mac)
# mac显示风格2
mac.= mac_cisco dialect 
# 3 display style MAC
Print (MAC)
= mac_bare mac.dialect 
Print (MAC) 

# MAC address manufacturer information 
print (mac.info)

 

Guess you like

Origin www.cnblogs.com/andy9468/p/11311088.html