IP地址处理
2017-11-23 本文已影响27人
王哲理
wget https://pypi.python.org/packages/source/I/IPy/IPy-0.81.tar.gz --no-check-certificate
#!/usr/bin/env python
from IPy import IP
ip_s = raw_input('Please input an IP or net-range: ')
ips = IP(ip_s)
if len(ips) > 1:
print ('net: %s' % ips.net())
print ('netmask: %s' % ips.netmask())
print ('broadcast: %s' % ips.broadcast())
print ('reverse address: %s' % ips.reverseNames()[0])
print ('subnet: %s' % len(ips))
else:
print ('reverse address: %s' % ips.reverseNames()[0])
print ('hexadecimal: %s' % ips.strHex())
print ('binary ip: %s' % ips.strBin())
print ('iptype: %s' % ips.iptype())