ping multiple Ips with python

darrell dgallion1 at yahoo.com
Sun Jan 5 01:21:07 CET 2003


Didn't mess with the checksum since it works and it's fast enough.
The pyrex code was cool to look at.

Added the following and a thread to improve responsiveness.
Using ipRange(), you can map your network.
Someone could find some traceroute code and find rounters.

I don't need this for hacking. It will help some of my customers.
--Darrell

def expand(v):
    if v.find("*")== -1:
        return [int(v)]
        
    if len(v) ==4:
        v=v.replace("*",'')
        v=int(v)
        return xrange(v,255)
        
    if v=='*':
        return xrange(1,255)
        
    assert int(v[0]) <= 2
    if len(v)==2:
        v+='*'
    vL=int(v.replace('*','0'))
    vH=min(254, int(v.replace('*','9')))
    return xrange(vL,vH+1)
    
    
def testExpand():
    assert list(expand("*"))  ==range(1,255)
    assert list(expand("2*")) ==range(200,255)
    assert list(expand("02*")) ==range(20,30)
    assert list(expand("21*"))==range(210,220)
    assert list(expand("233*"))==range(233,255)
    
testExpand()

def ipRange(val):
    vals=val.split(".")
    secondOctent= expand(vals[2])
    firstOctent = expand(vals[3])
    
    out=[]
    base=[vals[0],vals[1]] # Don't allow '*' in the first two octents
    
    for two in expand(vals[2]):
        for one in expand(vals[3]):
            out.append('.'.join(base+[str(two),str(one)]) )
            
    return out
    






More information about the Python-list mailing list