TELNET instead PING

DCK dck at gazeta.pl
Mon Jan 26 12:32:17 CET 2004


Hello :)

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 :) ):



"""
TelPing.py
- Simple Python script to probe workstation in WinNT Network

(c) 2004 Michal Kaczor (26.01.2004)
dck at gazeta.pl
"""

import telnetlib
import sys


def tel_ping(tn_host,tn_port):
    try:
        tn = telnetlib.Telnet(tn_host,tn_port)
        print 'Host:',tn_host,' Port:',tn_port,' <-- CONNECTED'
        tn.close()        
    except:
        print 'Host:',tn_host,' Port:',tn_port,' <-- Error: NO CONNECTION'


def main():
    if (len(sys.argv)==3):
       tel_ping(sys.argv[1],sys.argv[2])
    else:
       print 'Usage: telping.py <host> <port>'

if __name__ == "__main__":
   main()



More information about the Python-list mailing list