Chinaunix首页 | 论坛 | 博客
  • 博客访问: 7446263
  • 博文数量: 1758
  • 博客积分: 18684
  • 博客等级: 上将
  • 技术积分: 16252
  • 用 户 组: 普通用户
  • 注册时间: 2010-06-02 10:28
个人简介

啥也没写

文章分类

全部博文(1758)

文章存档

2024年(4)

2023年(44)

2022年(39)

2021年(46)

2020年(43)

2019年(27)

2018年(44)

2017年(50)

2016年(47)

2015年(15)

2014年(21)

2013年(43)

2012年(143)

2011年(228)

2010年(263)

2009年(384)

2008年(246)

2007年(30)

2006年(38)

2005年(2)

2004年(1)

分类: LINUX

2010-06-06 23:33:19

  作为一名SA,常与IP、网络打交道,自然少不了关于IP地址的处理,现给大家推荐一个非常棒的python IP处理模块,它类似于。能够处理IPV4及IPV6的地址。

下载地址
引用



安装
引用

tar -zxvf IPy-0.42.tar.gz
cd IPy-0.42
python setup.py install

简单例子
  1. >>> import IPy   
  2. >>> IPy.IP('10.0.0.0/8').version()   
  3. 4   
  4. >>> IPy.IP('::1').version()   
  5. 6   
  6. >>> print IPy.IP(0x7f000001)   
  7. 127.0.0.1   
  8. >>> print IPy.IP('0x7f000001')   
  9. 127.0.0.1   
  10. >>> print IPy.IP('127.0.0.1')   
  11. 127.0.0.1   
  12. >>> print IPy.IP('10')   
  13. 10.0.0.0   
  14.   
  15. >>> print IPy.IP('1080:0:0:0:8:800:200C:417A')   
  16. 1080:0000:0000:0000:0008:0800:200c:417a   
  17. >>> print IPy.IP('1080::8:800:200C:417A')   
  18. 1080:0000:0000:0000:0008:0800:200c:417a   
  19. >>> print IPy.IP('::1')   
  20. 0000:0000:0000:0000:0000:0000:0000:0001   
  21. >>> print IPy.IP('::13.1.68.3')   
  22. 0000:0000:0000:0000:0000:0000:0d01:4403   
  23.   
  24. >>> print IPy.IP('127.0.0.0/8')   
  25. 127.0.0.0/8   
  26. >>> print IPy.IP('127.0.0.0/255.0.0.0')   
  27. 127.0.0.0/8   
  28. >>> print IPy.IP('127.0.0.0-127.255.255.255')   
  29. 127.0.0.0/8   
  30.   
  31. >>> IPy.IP('10.0.0.0/24').strNormal(q)   
  32. '10.0.0.0/24'   
  33. >>> IPy.IP('10.0.0.0/24').strNormal(2)   
  34. '10.0.0.0/255.255.255.0'   
  35. >>> IPy.IP('10.0.0.0/24').strNormal(3)   
  36. '10.0.0.0-10.0.0.255'   
阅读(1253) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~