On 9/25/07, Moore, Greg <Greg_W_Moore@adp.com> wrote:
Hi,

Maybe someone can shed some light on this. I just want to quickly see if
a server is 'there' so I was playing around with functions in the socket
lib like gethostbyname and gethostbyaddr. I read Alan Kennedy's
NewSocketModule page on the wiki but it didn't seem to apply to this.

If I use Python I get this:

>>> import socket
>>> socket.gethostbyaddr('127.0.0.127 ')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
socket.herror: (11004, 'host not found')
>>>

Since 127.0.0.127 doesn't exist, this is what I expected. But If I use
Jyhton 2.2 the results are different as seen below.
Jython 2.2 on java1.4.2_07
Type "copyright", "credits" or "license" for more information.
>>> import socket
>>> gethostbyaddr('127.0.0.127')
('127.0.0.127', ['127.0.0.127 '], ['127.0.0.127'])
>>>

Is there a better way to do this?

Regards,
Greg.


May be you can connect with a small time out value and if it fails, you can conclude that the machine is not reachable.