IPy处理IP地址
1.下载:
pip install IPy
2.方法使用:
from IPy import IP
# 117.78.0.0/21
ip_obj = IP("117.78.0.0/21")
# i.net() 类型为<class 'IPy.IP'>对象
# 通过对象.strNormal 获取当前对象IP
ip_list = [i.net().strNormal() for i in ip_obj]
print(ip_list)
IP("192.168.1.1").version()
# 4
# 为IPV4类型
ip_obj = IP("117.78.0.0/21")
print(ip_obj.len())
# 2048
ip = IP("192.168.1.1")
print(ip.iptype())
# PUBLIC 表示公有
ip = IP("182.92.100.182")
print(ip.iptype())
# PRIVATE 表示私有
ip = IP("192.168.1.1")
print(ip.reverseName())
# 1.1.168.192.in-addr.arpa.
ip = IP("192.168.1.1")
print(ip.int())
# 3232235777
print(ip.strHex())
# 0xc0a80101
print(ip.strBin())
# 11000000101010000000000100000001
ip = IP("117.78.0.2")
print(ip.make_net("255.255.255.0"))
# 117.78.0.0/24
print(IP("117.78.0.2/255.255.255.0",make_net = True))
# 117.78.0.0/24
print(IP("117.78.0.0/21").overlaps("117.78.0.0/24"))
# 1
print(IP("117.78.0.0/21").overlaps("117.88.0.0/24"))
# 0
# 1表示重叠,0表示不重叠
ip = IP("117.78.0.2")
print(ip.netmask())
# 255.255.255.255
print(ip.broadcast())