Python论坛  - 讨论区

标题:[python-chinese] 请问怎么快速的生成IP列表

2008年01月06日 星期日 10:35

fluke.l fluke.l在gmail.com
星期日 一月 6 10:35:14 HKT 2008

一个HTML附件被移除...
URL: http://python.cn/pipermail/python-chinese/attachments/20080106/8a484624/attachment.html 

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2008年01月06日 星期日 14:51

篱笆 nameliba在gmail.com
星期日 一月 6 14:51:22 HKT 2008

a=1
b=1
for a in range(a,255):
    for  b in range(b,255):
        print str(a)+"."+ str(b)
...后面2个段自己加上就行了

在 08-1-6,fluke.l<fluke.l在gmail.com> 写道:
> 多少个段就多少重循环来从右边生成,跳过一些保留地址就好了,毕竟是递增的。
>
>  另外一种办法是写成二进制,增加主机位,满了再加网络号。再一边换成点分十进制表示。
>
>  -----------------------
>  欢迎使用手机浏览器UCWEB
>
>  ---原邮件---
>  发件人:searun
>  发送时间:2008-01-06 10:13
>  收件人:python-chinese
>  主题:[python-chinese] 请问怎么快速的生成IP列表
>
>  现在给定一个字符串: x.x.x.x - x.x.x.x,怎么快速的生成在这两个IP域之间的所有IP?
>  比如 1.1.1.2 - 1.1.1.5 生成
>  ('1.1.1.2','1.1.1.3','1.1.1.4','1.1.1.5')
>
>  我现在的做法是一个一个比较过来,代码写得非常臃肿。
>  _______________________________________________
>  python-chinese
>  Post: send python-chinese在lists.python.cn
>  Subscribe: send subscribe to python-chinese-request在lists.python.cn
>  Unsubscribe: send unsubscribe to  python-chinese-request在lists.python.cn
>  Detail Info: http://python.cn/mailman/listinfo/python-chinese

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2008年01月07日 星期一 00:07

Shao Feng sevenever在gmail.com
星期一 一月 7 00:07:06 HKT 2008

IP就是32位整数啊,
a='172.31.0.1'
b='172.31.2.255'

def ip2str(ip):
     return
'.'.join([str(ip/16777216),str(ip%16777216/65536),str(ip%65536/256),str(ip%256)])

ip=a.split('.')
ipa=int(ip[0])*256*256*256+int(ip[1])*65536+int(ip[2])*256+int(ip[3])
ip=b.split('.')
ipa=int(ip[0])*256*256*256+int(ip[1])*65536+int(ip[2])*256+int(ip[3])

for i in range(ipa, ipb+1):
    print(ip2str(i))

On Jan 6, 2008 2:51 PM, 篱笆 <nameliba在gmail.com> wrote:

> a=1
> b=1
> for a in range(a,255):
>    for  b in range(b,255):
>        print str(a)+"."+ str(b)
> ...后面2个段自己加上就行了
>
> 在 08-1-6,fluke.l<fluke.l在gmail.com> 写道:
> > 多少个段就多少重循环来从右边生成,跳过一些保留地址就好了,毕竟是递增的。
> >
> >  另外一种办法是写成二进制,增加主机位,满了再加网络号。再一边换成点分十进制表示。
> >
> >  -----------------------
> >  欢迎使用手机浏览器UCWEB
> >
> >  ---原邮件---
> >  发件人:searun
> >  发送时间:2008-01-06 10:13
> >  收件人:python-chinese
> >  主题:[python-chinese] 请问怎么快速的生成IP列表
> >
> >  现在给定一个字符串: x.x.x.x - x.x.x.x,怎么快速的生成在这两个IP域之间的所有IP?
> >  比如 1.1.1.2 - 1.1.1.5 生成
> >  ('1.1.1.2','1.1.1.3','1.1.1.4','1.1.1.5')
> >
> >  我现在的做法是一个一个比较过来,代码写得非常臃肿。
> >  _______________________________________________
> >  python-chinese
> >  Post: send python-chinese在lists.python.cn
> >  Subscribe: send subscribe to python-chinese-request在lists.python.cn
> >  Unsubscribe: send unsubscribe to
> python-chinese-request在lists.python.cn
> >  Detail Info: http://python.cn/mailman/listinfo/python-chinese
> _______________________________________________
> python-chinese
> Post: send python-chinese在lists.python.cn
> Subscribe: send subscribe to python-chinese-request在lists.python.cn
> Unsubscribe: send unsubscribe to  python-chinese-request在lists.python.cn
> Detail Info: http://python.cn/mailman/listinfo/python-chinese
>
-------------- 下一部分 --------------
一个HTML附件被移除...
URL: http://python.cn/pipermail/python-chinese/attachments/20080107/8289327e/attachment.htm 

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2008年01月07日 星期一 10:44

Jiahua Huang jhuangjiahua在gmail.com
星期一 一月 7 10:44:44 HKT 2008

赞~

On Jan 7, 2008 12:07 AM, Shao Feng <sevenever at gmail.com> wrote:
> IP就是32位整数啊,
>
> a='172.31.0.1'
> b='172.31.2.255'
>
> def ip2str(ip):
>      return
> '.'.join([str(ip/16777216),str(ip%16777216/65536),str(ip%65536/256),str(ip%256)])
>
>  ip=a.split('.')
> ipa=int(ip[0])*256*256*256+int(ip[1])*256*256+int(ip[2])*256+int(ip[3])
> ip=b.split('.')
>  ipb=int(ip[0])*256*256*256+int(ip[1])*256*256+int(ip[2])*256+int(ip[3])
>
> for i in range(ipa, ipb+1):
>     print(ip2str(i))
>

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2008年01月07日 星期一 14:40

Li Qingfeng liqfemail在gmail.com
星期一 一月 7 14:40:49 HKT 2008

"IP¾ÍÊÇ32λÕûÊý°¡"£¬Ò»ÓïµÀÆÆ±¾ÖÊ£¬ÔÞ£¡

ÔÚ08-1-7£¬Shao Feng <sevenever在gmail.com> дµÀ£º
>
> IP¾ÍÊÇ32λÕûÊý°¡£¬
> a='172.31.0.1'
> b='172.31.2.255'
>
> def ip2str(ip):
>      return
> '.'.join([str(ip/16777216),str(ip%16777216/65536),str(ip%65536/256),str(ip%256)])
>
>
> ip=a.split('.')
> ipa=int(ip[0])*256*256*256+int(ip[1])*65536+int(ip[2])*256+int(ip[3])
> ip=b.split('.')
> ipa=int(ip[0])*256*256*256+int(ip[1])*65536+int(ip[2])*256+int(ip[3])
>
> for i in range(ipa, ipb+1):
>     print(ip2str(i))
>
> On Jan 6, 2008 2:51 PM, Àé°Ê < nameliba在gmail.com> wrote:
>
> > a=1
> > b=1
> > for a in range(a,255):
> >    for  b in range(b,255):
> >        print str(a)+"."+ str(b)
> > ...ºóÃæ2¸ö¶Î×Ô¼º¼ÓÉϾÍÐÐÁË
> >
> > ÔÚ 08-1-6£¬fluke.l<fluke.l在gmail.com> дµÀ£º
> > > ¶àÉÙ¸ö¶Î¾Í¶àÉÙÖØÑ­»·À´´ÓÓÒ±ßÉú³É£¬Ìø¹ýһЩ±£ÁôµØÖ·¾ÍºÃÁË£¬±Ï¾¹ÊǵÝÔöµÄ¡£
> > >
> > >  ÁíÍâÒ»ÖÖ°ì·¨ÊÇд³É¶þ½øÖÆ£¬Ôö¼ÓÖ÷»ú룬ÂúÁËÔÙ¼ÓÍøÂçºÅ¡£ÔÙÒ»±ß»»³Éµã·ÖÊ®½øÖƱíʾ¡£
> > >
> > >  -----------------------
> > >  »¶Ó­Ê¹ÓÃÊÖ»úä¯ÀÀÆ÷UCWEB
> > >
> > >  ---Ô­Óʼþ---
> > >  ·¢¼þÈË:searun
> > >  ·¢ËÍʱ¼ä:2008-01-06 10:13
> > >  ÊÕ¼þÈË:python-chinese
> > >  Ö÷Ìâ:[python-chinese] ÇëÎÊÔõô¿ìËÙµÄÉú³ÉIPÁбí
> > >
> > >  ÏÖÔÚ¸ø¶¨Ò»¸ö×Ö·û´®: x.x.x.x - x.x.x.x£¬Ôõô¿ìËÙµÄÉú³ÉÔÚÕâÁ½¸öIPÓòÖ®¼äµÄËùÓÐIP£¿
> > >  ±ÈÈç 1.1.1.2 - 1.1.1.5 Éú³É
> > >  ('1.1.1.2','1.1.1.3','1.1.1.4',' 1.1.1.5')
> > >
> > >  ÎÒÏÖÔÚµÄ×ö·¨ÊÇÒ»¸öÒ»¸ö±È½Ï¹ýÀ´£¬´úÂëдµÃ·Ç³£Ó·Öס£
> > >  _______________________________________________
> > >  python-chinese
> > >  Post: send python-chinese在lists.python.cn
> > >  Subscribe: send subscribe to python-chinese-request在lists.python.cn
> > >  Unsubscribe: send unsubscribe to  python-chinese-request在lists.python.cn
> > >  Detail Info: http://python.cn/mailman/listinfo/python-chinese
> > _______________________________________________
> > python-chinese
> > Post: send python-chinese在lists.python.cn
> > Subscribe: send subscribe to python-chinese-request在lists.python.cn
> > Unsubscribe: send unsubscribe to  python-chinese-request在lists.python.cn
> > Detail Info: http://python.cn/mailman/listinfo/python-chinese
> >
>
>
> _______________________________________________
> python-chinese
> Post: send python-chinese在lists.python.cn
> Subscribe: send subscribe to python-chinese-request在lists.python.cn
> Unsubscribe: send unsubscribe to  python-chinese-request在lists.python.cn
> Detail Info: http://python.cn/mailman/listinfo/python-chinese
>
-------------- 下一部分 --------------
Ò»¸öHTML¸½¼þ±»ÒƳý...
URL: http://python.cn/pipermail/python-chinese/attachments/20080107/ba049f59/attachment-0001.html 

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2008年01月07日 星期一 16:52

Samuel Chi princeofdatamining在gmail.com
星期一 一月 7 16:52:30 HKT 2008

IPv6ÄØ??

ÔÚ08-1-7£¬Li Qingfeng <liqfemail在gmail.com> дµÀ£º
>
> "IP¾ÍÊÇ32λÕûÊý°¡"£¬Ò»ÓïµÀÆÆ±¾ÖÊ£¬ÔÞ£¡
>
> ÔÚ08-1-7£¬Shao Feng <sevenever在gmail.com> дµÀ£º
> >
> > IP¾ÍÊÇ32λÕûÊý°¡£¬
> > a='172.31.0.1'
> > b=' 172.31.2.255'
> >
> > def ip2str(ip):
> >      return
> > '.'.join([str(ip/16777216),str(ip%16777216/65536),str(ip%65536/256),str(ip%256)])
> >
> >
> > ip=a.split('.')
> > ipa=int(ip[0])*256*256*256+int(ip[1])*65536+int(ip[2])*256+int(ip[3])
> > ip=b.split('.')
> > ipa=int(ip[0])*256*256*256+int(ip[1])*65536+int(ip[2])*256+int(ip[3])
> >
> > for i in range(ipa, ipb+1):
> >     print(ip2str(i))
> >
> > On Jan 6, 2008 2:51 PM, Àé°Ê < nameliba在gmail.com> wrote:
> >
> > > a=1
> > > b=1
> > > for a in range(a,255):
> > >    for  b in range(b,255):
> > >        print str(a)+"."+ str(b)
> > > ...ºóÃæ2¸ö¶Î×Ô¼º¼ÓÉϾÍÐÐÁË
> > >
> > > ÔÚ 08-1-6£¬fluke.l<fluke.l在gmail.com > дµÀ£º
> > > > ¶àÉÙ¸ö¶Î¾Í¶àÉÙÖØÑ­»·À´´ÓÓÒ±ßÉú³É£¬Ìø¹ýһЩ±£ÁôµØÖ·¾ÍºÃÁË£¬±Ï¾¹ÊǵÝÔöµÄ¡£
> > > >
> > > >  ÁíÍâÒ»ÖÖ°ì·¨ÊÇд³É¶þ½øÖÆ£¬Ôö¼ÓÖ÷»ú룬ÂúÁËÔÙ¼ÓÍøÂçºÅ¡£ÔÙÒ»±ß»»³Éµã·ÖÊ®½øÖƱíʾ¡£
> > > >
> > > >  -----------------------
> > > >  »¶Ó­Ê¹ÓÃÊÖ»úä¯ÀÀÆ÷UCWEB
> > > >
> > > >  ---Ô­Óʼþ---
> > > >  ·¢¼þÈË:searun
> > > >  ·¢ËÍʱ¼ä:2008-01-06 10:13
> > > >  ÊÕ¼þÈË:python-chinese
> > > >  Ö÷Ìâ:[python-chinese] ÇëÎÊÔõô¿ìËÙµÄÉú³ÉIPÁбí
> > > >
> > > >  ÏÖÔÚ¸ø¶¨Ò»¸ö×Ö·û´®: x.x.x.x - x.x.x.x£¬Ôõô¿ìËÙµÄÉú³ÉÔÚÕâÁ½¸öIPÓòÖ®¼äµÄËùÓÐIP£¿
> > > >  ±ÈÈç 1.1.1.2 - 1.1.1.5 Éú³É
> > > >  ('1.1.1.2',' 1.1.1.3','1.1.1.4',' 1.1.1.5')
> > > >
> > > >  ÎÒÏÖÔÚµÄ×ö·¨ÊÇÒ»¸öÒ»¸ö±È½Ï¹ýÀ´£¬´úÂëдµÃ·Ç³£Ó·Öס£
> > > >  _______________________________________________
> > > >  python-chinese
> > > >  Post: send python-chinese在lists.python.cn
> > > >  Subscribe: send subscribe to python-chinese-request在lists.python.cn
> > > >  Unsubscribe: send unsubscribe to
> > > python-chinese-request在lists.python.cn
> > > >  Detail Info: http://python.cn/mailman/listinfo/python-chinese
> > > _______________________________________________
> > > python-chinese
> > > Post: send python-chinese在lists.python.cn
> > > Subscribe: send subscribe to python-chinese-request在lists.python.cn
> > > Unsubscribe: send unsubscribe to
> > > python-chinese-request在lists.python.cn
> > > Detail Info: http://python.cn/mailman/listinfo/python-chinese
> > >
> >
> >
> > _______________________________________________
> > python-chinese
> > Post: send python-chinese在lists.python.cn
> > Subscribe: send subscribe to python-chinese-request在lists.python.cn
> > Unsubscribe: send unsubscribe to
> > python-chinese-request在lists.python.cn
> > Detail Info: http://python.cn/mailman/listinfo/python-chinese
> >
>
>
> _______________________________________________
> python-chinese
> Post: send python-chinese在lists.python.cn
> Subscribe: send subscribe to python-chinese-request在lists.python.cn
> Unsubscribe: send unsubscribe to  python-chinese-request在lists.python.cn
> Detail Info: http://python.cn/mailman/listinfo/python-chinese
>
-------------- 下一部分 --------------
Ò»¸öHTML¸½¼þ±»ÒƳý...
URL: http://python.cn/pipermail/python-chinese/attachments/20080107/fb8e4933/attachment.html 

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2008年01月11日 星期五 09:19

ww wang.wei在software.eteda.com
星期五 一月 11 09:19:53 HKT 2008

´Õ¸öÈÈÄÖ

a='172.31.0.1'
b='172.31.2.255'

def ip2str(ip):
    ret=[]
    for i in range(4):
        ret.insert(0,str(ip%256))
        ip=int(ip/256)
    return '.'.join(ret)
    
def str2ip(sip):
    ret=0
    ip=sip.split('.')
    for i in range(4):
        ret=ret*256+int(ip.pop(0))
    return ret
    
for i in range(str2ip(a),str2ip(b)+1):
    print ip2str(i)
    

On Mon, 7 Jan 2008 00:07:06 +0800
"Shao Feng" <sevenever在gmail.com> wrote:

> IPA¥32ˆÊ®”?C
> a='172.31.0.1'
> b='172.31.2.255'
> 
> def ip2str(ip):
>      return
> '.'.join([str(ip/16777216),str(ip%16777216/65536),str(ip%65536/256),str(ip%256)])
> 
> ip=a.split('.')
> ipa=int(ip[0])*256*256*256+int(ip[1])*65536+int(ip[2])*256+int(ip[3])
> ip=b.split('.')
> ipa=int(ip[0])*256*256*256+int(ip[1])*65536+int(ip[2])*256+int(ip[3])
> 
> for i in range(ipa, ipb+1):
>     print(ip2str(i))
> 
> On Jan 6, 2008 2:51 PM, ?■<nameliba在gmail.com> wrote:
> 
> > a=1
> > b=1
> > for a in range(a,255):
> >    for  b in range(b,255):
> >        print str(a)+"."+ str(b)
> > ...@–Ê2˜¢’iŽ©ŒÈ‰ÁãAs—¹
> >
> > Ý 08-1-6Cfluke.l<fluke.l在gmail.com> ŽÊ“¹F
> > > ‘½­˜¢’iA‘½­dz?—ˆ˜¸‰E?¶¬C’µ?ˆê±•Û—¯’nš¬AD—¹C?è퐥?ú“IB
> > >
> > >  ?ŠOˆê??–@¥ŽÊ¬“ñ?§Cú‰ÁŽåŠ÷ˆÊC?—¹Ä‰Áã¤?†BÄˆê??¬“_•ª\?§•\ަB
> > >
> > >  -----------------------
> > >  ?Œ}Žg—pŽèŠ÷??ŠíUCWEB
> > >
> > >  ---Œ´?Œ---
> > >  ?Œl:searun
> > >  ?‘—??:2008-01-06 10:13
> > >  ¾Œl:python-chinese
> > >  Žå?:[python-chinese] ??œƒ?‰õ‘¬“I¶¬IP—ñ•\
> > >
> > >  ?Ý?’èˆê˜¢Žš•„‹ø: x.x.x.x - x.x.x.xCœƒ?‰õ‘¬“I¶¬Ý??˜¢IPˆæ”V?“IŠ—LIPH
> > >  ”ä”@ 1.1.1.2 - 1.1.1.5 ¶¬
> > >  ('1.1.1.2','1.1.1.3','1.1.1.4','1.1.1.5')
> > >
> > >  ‰ä?Ý“I˜ô–@¥ˆê˜¢ˆê˜¢”ä??—ˆC‘ã?ŽÊ“¾”ñí??B
> > >  _______________________________________________
> > >  python-chinese
> > >  Post: send python-chinese在lists.python.cn
> > >  Subscribe: send subscribe to python-chinese-request在lists.python.cn
> > >  Unsubscribe: send unsubscribe to
> > python-chinese-request在lists.python.cn
> > >  Detail Info: http://python.cn/mailman/listinfo/python-chinese
> > _______________________________________________
> > python-chinese
> > Post: send python-chinese在lists.python.cn
> > Subscribe: send subscribe to python-chinese-request在lists.python.cn
> > Unsubscribe: send unsubscribe to  python-chinese-request在lists.python.cn
> > Detail Info: http://python.cn/mailman/listinfo/python-chinese
> >

--
ww <wang.wei在software.eteda.com>


[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

如下红色区域有误,请重新填写。

    你的回复:

    请 登录 后回复。还没有在Zeuux哲思注册吗?现在 注册 !

    Zeuux © 2025

    京ICP备05028076号