版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_34777982/article/details/82500975
#根据ip或者子网返回网络 掩码 广播 反向解析 子网数 ip类型等信息
from IPy import IP
ip_s = input("请输入ip地址或网段:")
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.strHex())
#二进制
print('binary ip: %s' % ips.strBin())
#地址类型
print('iptype: %s' % ips.iptype())