TELNET instead PING

Discussion in 'Python' started by DCK, Jan 26, 2004.

  1. DCK

    DCK Guest

    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)

    """

    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()
    DCK, Jan 26, 2004
    #1
    1. Advertising

  2. DCK wrote:
    > 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 :) ):


    thanks a lot.
    Can you do the same using ARP who-has request ? :)
    Serge A. Ribalchenko, Jan 26, 2004
    #2
    1. Advertising

  3. DCK

    Peter Hansen Guest

    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
    Peter Hansen, Jan 26, 2004
    #3
  4. DCK

    Gandalf Guest

    Peter Hansen wrote:

    >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.
    >
    >

    Exactly. All you need is an open port you can check.

    Note: that reason you talked about is most likely a packet filtering
    firewall. A good firewall
    can block PING, Telnet, Nbsession and many others. In most cases, the
    best policy
    is to lock everything by default and permit only the ones you really
    want. Firewall
    rules can include source addresses too. It is possible that a computer
    do not respond
    on PING and TELNET ports for you but it does for a similar request from
    another
    computer. I think there is no universal way to determine if a remote
    host is alive or not.
    Gandalf, Jan 26, 2004
    #4
  5. DCK

    Peter Hansen Guest

    > Gandalf wrote:
    >
    > I think there is no universal way to determine if a remote host is alive or not.


    That is definitely the case, because of course the firewall could just as
    easily block all traffic that is not from a specific IP address as well.

    -Peter
    Peter Hansen, Jan 26, 2004
    #5
  6. Gandalf wrote:


    > Note: that reason you talked about is most likely a packet filtering
    > firewall. A good firewall
    > can block PING, Telnet, Nbsession and many others. In most cases, the
    > best policy
    > is to lock everything by default and permit only the ones you really
    > want. Firewall
    > rules can include source addresses too. It is possible that a computer
    > do not respond
    > on PING and TELNET ports for you but it does for a similar request from
    > another
    > computer. I think there is no universal way to determine if a remote
    > host is alive or not.


    If we are talking about IP network segment in the same ethernet layer,
    can you ignore my ARP request - who-has <your-ip> ?
    Serge A. Ribalchenko, Jan 27, 2004
    #6
  7. DCK

    Gandalf Guest

    >
    >> Note: that reason you talked about is most likely a packet filtering
    >> firewall. A good firewall
    >> can block PING, Telnet, Nbsession and many others. In most cases, the
    >> best policy
    >> is to lock everything by default and permit only the ones you really
    >> want. Firewall
    >> rules can include source addresses too. It is possible that a
    >> computer do not respond
    >> on PING and TELNET ports for you but it does for a similar request
    >> from another
    >> computer. I think there is no universal way to determine if a remote
    >> host is alive or not.

    >
    >
    > If we are talking about IP network segment in the same ethernet layer,
    > can you ignore my ARP request - who-has <your-ip> ?
    >

    Probably I cannot. :)
    But this applies only when you are in the same segment.
    By the way, is it possible to send an ARP request from pure Python? ;-)
    AFAIK Python provides tools for level 3 and above only.
    Gandalf, Jan 27, 2004
    #7
  8. DCK

    DCK Guest

    Peter Hansen wrote:
    > 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.

    I was on some kind of Network course, where teacher said, that telnet
    is better then PING. In my work i found this usefull for pinging
    network. When i meet with Python, i foud TELNETLIB module and write
    simply scheduled script which probe network.

    > 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'


    THX for this advice. In future i will read manual carefully :)

    Greetz
    Michal DCK Kaczor
    DCK, Jan 27, 2004
    #8
  9. -----BEGIN PGP SIGNED MESSAGE-----
    Hash: SHA1

    At 2004-01-27T11:11:22Z, "DCK" <> writes:

    > I was on some kind of Network course, where teacher said, that telnet is
    > better then PING.


    Your teacher was on crack. That's like saying that "table lamps are better
    than pencil cups". :)
    - --
    Kirk Strauser
    The Strauser Group
    Open. Solutions. Simple.
    http://www.strausergroup.com/
    -----BEGIN PGP SIGNATURE-----
    Version: GnuPG v1.2.4 (GNU/Linux)

    iD8DBQFAFn/T5sRg+Y0CpvERAq0UAJ9WhPxMY1Um93QwcOLqGHy+0KlcQgCeJbdW
    4o7kvcO5ryEZ8HrSwDy7o9c=
    =kPeN
    -----END PGP SIGNATURE-----
    Kirk Strauser, Jan 27, 2004
    #9
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. bernd wegener

    Piping ping into perl-prog

    bernd wegener, Sep 15, 2004, in forum: Perl
    Replies:
    3
    Views:
    646
    Jim Gibson
    Sep 22, 2004
  2. Fábio

    ping

    Fábio, Jul 2, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    602
    Fábio
    Jul 2, 2003
  3. Fábio

    Ping in ASP.NET

    Fábio, Jul 2, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    488
    Fabio
    Jul 2, 2003
  4. Jim Isaacson
    Replies:
    5
    Views:
    593
    Default User
    Nov 5, 2004
  5. Carcarius
    Replies:
    0
    Views:
    275
    Carcarius
    Dec 6, 2007
Loading...

Share This Page