1.安裝 netaddr 組件 pip install netaddr -i https://mirrors.aliyun.com/pypi/simple/ from netaddr import IPNetwork print('https://ipjisuanqi.com/#121.224.14 ...
1.安裝 netaddr 組件
pip install netaddr -i https://mirrors.aliyun.com/pypi/simple/
from netaddr import IPNetwork print('https://ipjisuanqi.com/#121.224.143.188') ip_str = "121.224.143.188/28" ip = IPNetwork(ip_str) print(ip) print('============> 30 <=============') # 修改地址的掩碼長度為28 ip.prefixlen = 30 print(ip) print('網路地址 => %s' % ip.network) print('網掩碼位 => %s' % ip.prefixlen) print('子網掩碼 => %s' % ip.netmask) ipIdx = 0; for item in ip.iter_hosts(): ipIdx = ipIdx + 1 print('可用IP %s = > %s' % (ipIdx, item)) print('可用IP數量 => %s' % ipIdx) print('廣播地址 => %s' % ip.broadcast) print('============> 以上實現了網站中獲取的信息 <=============')
print('============> IPAddress的用法 <=============') from netaddr import IPAddress # 判斷地址的公網、私網屬性 print(IPAddress("121.224.143.188").is_private()) print(IPAddress("192.168.0.1").is_private())