samuel / python-ping

Pure Python version of ICMP ping
229 stars 309 forks source link

Update ping.py (filter out request messages) #2

Closed obeleh closed 9 years ago

obeleh commented 9 years ago

Changed receive response to not accept ICMP request messages. It was possible to receive the very request that was sent.

samuel commented 9 years ago

Thanks for the patch.

obeleh commented 9 years ago

I was wondering. The current code is not thread safe because it uses the same packetID and sequence number over and over again.

Would you like me to provide a patch so that PacketId and Sequence Number are generated as follows:

def genId(ip):
    # based on IP
    return int(hashlib.sha1(ip).hexdigest(), 16) % 32768

def genSeq():
    # based on Time
    return int(time.time() * 10000.0) % 32768

Another possibility for genId would be to convert the IP to an integer and then modulo it.