IPy模块 – 方便处理绝大部分的IPv6及IPv4的网络和地址
其使用如下:
# coding=utf-8
"""
@version: ??
@author: AA-ldc
@file: testIP.py
@time: 2017/3/31 14:44
@function:IPy模块
"""
from IPy import IP
ip_s = raw_input('Please input an IP or net-range: ')
ips = IP(ip_s)
print len(ips)
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())