Home >Backend Development >Python Tutorial >python生成IP段的方法

python生成IP段的方法

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-06 11:13:111556browse

本文实例讲述了python生成IP段的方法。分享给大家供大家参考。具体实现方法如下:

#!/usr/local/bin/python
#-*- coding: UTF-8 -*-
#############################################################
# python 生成IP段
#############################################################
if __name__ == '__main__':
  xxx=file('test.txt','w')
  for IP1 in range(254,0,-1):
    for IP2 in range(254,0,-1):
      #for IP3 in range(254,0,-1):
        #for IP4 in range(254,0,-1):
          #print IP1,IP2
        abc= '%s.%s.%s-%s.%s.%s\n' % (IP1,IP2,"1.1",
                    IP1,IP2,"255.255")
        xxx.write(abc)
  xxx.close()

运行效果如下图所示:

 

希望本文所述对大家的Python程序设计有所帮助。

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn