IPy

IPy
生成网段列表
from IPy import IP
ip = IP('192.168.0.0/16')
print ip.len()
for x in ip:
print (x)

ip的属性,'PUBLIC','PRIVATE'
ip = IPy.IP('12.3.1.3')
ip.iptype()

通过strNormal指定不同的wantprefixlen
IPy.IP('192.168.1.0/24').strNormal(3)

from IPy import IP
ip_s=raw_input('input 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('broadcast: %s' %ips.broadcast())#输出广播地址
print('subnet: %s' % len(ips))#子网数
else:#为单个ip

print('reverse: %s' % ips.reverseNames()[0])
print('hex: %s' % ips.strHex())
print('binary: %s' % ips.strBin())
print('iptype: %s' % ips.iptype())

posted on 2016-04-14 14:09  lly001  阅读(372)  评论(0编辑  收藏  举报

导航