TELNET instead PING

Peter Hansen peter at engcorp.com
Mon Jan 26 14:59:53 EST 2004


DCK wrote:
> 
> Into group-archive i found most e-mails, which touches PINGing.
> In my work i've used TELNET for testing if host is operational.
> Sometimes, for unknown reasons, workstation doesn't respond
> for PINGing. But in WinNT network, all hosts has a nbsession
> listening on port 139. I always use this script instead PING
> command (hope, will be usefull for someone :) ):

Interesting, but why would you use TELNET for that?  Telnet is
simply one of many possible protocols, whereas you need only
open a socket to the port to see if the host is responding.

from socket import *
s = socket(AF_INET, SOCK_STREAM)
try:
    s.connect((host, port))
    print 'host connected'
    s.close()
except error:
    print 'host not responding'

Should basically do the same job ...

-Peter



More information about the Python-list mailing list