# 用來(lái)區(qū)分IPv4 和 IPv6
from IPy import IP
print("127.0.0.1屬于IPv%s" % IP("127.0.0.1").version())
# [out]: 127.0.0.1屬于IPv4
# 輸出該網(wǎng)段下所有的IP地址
for ip in IP("10.2.0.0/31"):
print(ip)
# [out]:
# 10.2.0.0
# 10.2.0.1
ip = IP('192.168.1.20')
# 判斷是公網(wǎng)還是私網(wǎng)
print("192.168.1.20的網(wǎng)絡(luò)類型是" + ip.iptype()) # 192.168.1.20的網(wǎng)絡(luò)類型是PRIVATE
# 將IP轉(zhuǎn)化成整形
print("192.168.1.20 to int is %s" % ip.int()) # 192.168.1.20 to int is 3232235796
# 將整形轉(zhuǎn)化成IP
print("3232235796 is %s" % IP(3232235796)) # 3232235796 is 192.168.1.20