Python 之about IP

查看输入IP的相关信息

# -*- coding:utf-8 -*- 
from IPy import IP
#接受用户输入,参数为IP地址或网段地址
ip_s = input('Please input an IP or net-range: ').strip()
ips = IP(ip_s)
print('你输入的IP个数为: %s' % len(ips))
if len(ips) > 1:
    print('net: %s' % ips.net()) 
    print('netmask : %s' % ips.netmask()) 
    print('broadcast: %s' % ips.broadcast()) 
    print('revere 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())

输入网段

你输入的IP个数为: 256
net: 192.168.1.0
netmask : 255.255.255.0
broadcast: 192.168.1.255
revere address: 1.168.192.in-addr.arpa.
subnet: 256
hexadecimal: 0xc0a80100
binary ip: 11000000101010000000000100000000
iptype: PRIVATE

输入单个主机IP

你输入的IP个数为: 1
reverse address: 50.1.168.192.in-addr.arpa.
hexadecimal: 0xc0a80132
binary ip: 11000000101010000000000100110010
iptype: PRIVATE

注:个人学习之笔记,留作个人巩固用

END!

原文地址:https://www.cnblogs.com/changbo/p/5584396.html