根据输入的IP或子网返回网络、掩码、广播、反向解析、子网数、IP类型等信息
2016-09-07 15:12
483 查看
根据输入的IP或子网返回网络、掩码、广播、反向解析、子网数、IP类型等信息需要的模块为IPy模块 此处为python3版本
#!/usr/bin/env python # -*- coding:utf-8 -*- from IPy import IP ip_s = input('Please input an IP or net-range: ') #参数为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: #若上面Input的值为一个IP地址 print('reverse address: %s' % ips.reverseNames()[0]) #输出IP地址反向解析 print('hexadecimal: %s' % ips.strHex()) #输入16进制地址 print('binary ip: %s' % ips.strBin()) #2进制 print('iptype: %s' % ips.iptype()) #输出IP地址类型
运行结果:
[root@www python]# python IP1.pyPlease 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[root@www python]# python IP1.pyPlease input an IP or net-range: 192.168.1.102reverse address: 102.1.168.192.in-addr.arpa.hexadecimal: 0xc0a80166binary ip: 11000000101010000000000101100110iptype: PRIVATE
相关文章推荐
- 学习python自动化运维之输入IP或网段,返回网络.掩码等信息
- 如何通过一个IP和子网掩码得到网络地址和广播地址
- Linux下如何用C语言获得网络信息,比如IP,掩码,mac地址,网关
- 如何根据IP地址和子网掩码,计算其所在子网的网络地址,主机地址和广播地址 .
- Linux网络编程 - 域名与IP信息解析
- (转)根据IP返回对应的位置信息
- 子网-掩码-网关-网络地址-广播地址
- 安卓完成一个应用,用户可以根据自己输入的地址下载网络上的图片和网页信息
- 写给自己的网络请求解析 返回数组和字典类型不同的处理方法
- 地址栏中,输入不存在的ip和域名,浏览器返回信息的时长不一样
- 根据ip地址和掩码求网络地址,主机号,广播号和主机最大数。。
- Linux网络管理员手册(2) 第二章 TCP/IP网络的问题 IP地址 子网(Subnetworks) 域名服务器 解析
- 完成一个应用,用户可以根据自己输入的地址下载网络上的图片和网页信息
- java网络编程二:服务器处理多个用户请求的解决方案(返回多个用户输入的信息)
- 根据Ip地址与掩码 得出 子网地址与广播地址
- 如何根据IP地址和子网掩码,计算其所在子网的网络地址,主机地址和广播地址
- java网络编程二:服务器处理多个用户请求的解决方案(返回多个用户输入的信息)
- 根据IP地址返回IP的详细信息(Web Service)
- Android平台 用户可以根据自己输入的地址下载网络上的图片和网页信息
- java网络编程二:服务器处理多个用户请求的解决方案(返回多个用户输入的信息)