How to ping a machine in a simple way?

Lexy Zhitenev zhitenev at cs.vsu.ru
Tue May 13 13:57:39 EDT 2003


Hello, All.

I need to know if a remote host is available or not.
I have to ping it from Python.
I can't create SOCK_RAW sockets, so ping package can't help me.
My friend in Java just creates a socket on 139 port, and if it fails - the
machine is not available.
try {
sock = new Socket('host1', 139)
sock.close()
} except la-la ...

I tried the following code:
>>> sk = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
>>> sk.connect(('c1r383n09', 139)) # This should fail.
>>> sk.connect_ex(('c1r383n09', 139))
0

The host exists, but it is down.
And no exception. Can you please help me solve the problem?

I use ActivePython 2.2.2 on Windows 2000.


Thanks beforehand.
Regards, Lexy.






More information about the Python-list mailing list