最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
使用Python获取并处理IP的类型及格式方法
时间:2018-11-06 编辑:猪哥 来源:一聚教程网
公网与私有网络的判断其实十分简单,只要记住私有网络的三个网段。不过,对于记性不好的人或者学识不是很高的机器来说,有一种判断方法还是有必要的。
写如下脚本:
from IPy import IP ip1 = IP('192.168.1.2') ip2 = IP('11.12.13.14') print("ip1 type: %s" % ip1.iptype()) print("ip2 type: %s" % ip2.iptype()) print("ip2 int value: %d" % ip2.int()) print("ip2 hex value: %s" % ip2.strHex()) print("ip2 bin value: %s" % ip2.strBin()) print("IP for 0x1234567: %s" % IP(0x1234567))
运行结果如下:
ip1 type: PRIVATE ip2 type: PUBLIC ip2 int value: 185339150 ip2 hex value: 0xb0c0d0e ip2 bin value: 00001011000011000000110100001110 IP for 0x1234567: 1.35.69.103
从上面的结果可以看出:
1、ip1位私有地址;
2、ip2是公网地址;
3、IP的不同类型可以进行自由转换;
-
上一个: 使用Python进行目录的对比方法
相关文章
- Golang ProtoBuf的基本语法详解 10-20
- Python识别MySQL中的冗余索引解析 10-20
- Python+Pygame绘制小球代码展示 10-18
- Python中的数据精度问题介绍 10-18
- Python随机值生成的常用方法介绍 10-18
- python3解压缩.gz文件分析 09-27