Returns information such as Network, mask, broadcast, reverse resolution, subnet number, IP type, etc. based on the IP or subnet entered

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.