def ipAddrRange(startAddr, endAddr): def incrAddr(addrList): addrList[3] += 1 for i in (3,2,1): if addrList[i] == 256: addrList[i] = 0 addrList[i-1] += 1 def asString(addrList): return ".".join(map(str,addrList)) startAddrList = map(int,startAddr.split(".")) endAddrList = map(int,endAddr.split(".")) curAddrList = startAddrList[:] yield asString(curAddrList) for i in range(4): while curAddrList[i] < endAddrList[i]: incrAddr(curAddrList) yield asString(curAddrList) for addr in ipAddrRange("10.255.255.250","11.0.0.20"): print addr
Search This Blog
Thursday, February 12, 2009
IP Address Range Function in Python
Subscribe to:
Post Comments (Atom)
1 comment:
Just what I needed, and no modules to import. Thanks!
Post a Comment