I am using the python-pyip 0.7-1 Debian package in order to check a link availability. For this, I create a pinger object:
pinger = ping.Pinger(host, 1)
pinger.ping()
Sometimes (I cannot reproduce it), not very often, the ping() function raises this exception:
File "/usr/local/bin/novaping.py", line 18, in ?
pinger.ping()
File "/var/lib/python-support/python2.4/ping.py", line 106, in ping
self.wait()
File "/var/lib/python-support/python2.4/ping.py", line 128, in wait
if reply.get_id() == self.pid:
AttributeError: Unreachable instance has no attribute 'get_id'
I have checked ping.py code, and found this inside a loop:
repip = ip.disassemble(pkt)
try:
reply = icmp.disassemble(repip.data)
except ValueError:
continue
# use reply
Probably this is not the origin of the problem described, but anyway it seems incorrect to use "reply" without assuring that has a default value if ValueError was raised.
I just hit this problem as well.
The problem is that icmp.disassemble() is returning an object of type Unreachable, because it got an ICMP reply of ICMP_UNREACH, due to pinging a down host on the local LAN.
The code is failing to check that the ICMP packet that was successfully disassembled was indeed an EchoReply. It appears to be expecting a ValueError when given the wrong type of packet to decode, but the actual icmp module's classes only raise a ValueError if the contents of the packet don't match the type in their header.