Returns information such as Network, mask, broadcast, reverse resolution, subnet number, IP type, etc. based on the IP or subnet entered
Module required for IPY module here is the Python3 version
#!/usr/bin/env python# -*- coding:utf-8 -*-from ipy import ipip_s = input (' please input an ip or net-range: ') # Parameters are IP or network segment 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: #若上面Input的值为一个IP地址 print (' reverse address: %s ' % ips.reversenames () [0]) # Output IP Address Reverse resolution print (' hexadecimal: %s ' % ips.strhex ()) #输入16进制地址print (' binary ip: %s ' % ips.strbin ()) #2进制print (' iptype: %s ') % ips.iptype ()) #输出IP地址类型
Operation Result:
[email protected] python]# python ip1.py Please input an IP or net-range:192.168.1.0/24net:192.168.1.0netmask:255.255. 255.0broadcast:192.168.1.255reverse address:1.168.192.in-addr.arpa.subnet:256hexadecimal:0xc0a80100binary IP: 11000000101010000000000100000000iptype:privateyou have new mail In/var/spool/mail/root[[email protected] python]# Python ip1.py Please input an IP or Net-range:192.168.1.102reverse address:102.1.168.192.in-addr.arpa.hexadecimal:0xc0 A80166binary ip:11000000101010000000000101100110iptype:private
This article is from the "willing to share with you" blog, please be sure to keep this source http://pengjc.blog.51cto.com/9255463/1847307
Returns information such as Network, mask, broadcast, reverse resolution, subnet number, IP type, etc. based on the IP or subnet entered