TELNET instead PING

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • DCK

    TELNET instead PING

    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@gazeta.pl
    """

    import telnetlib
    import sys


    def tel_ping(tn_hos t,tn_port):
    try:
    tn = telnetlib.Telne t(tn_host,tn_po rt)
    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.ar gv[1],sys.argv[2])
    else:
    print 'Usage: telping.py <host> <port>'

    if __name__ == "__main__":
    main()
  • Serge A. Ribalchenko

    #2
    Re: TELNET instead PING

    DCK wrote:[color=blue]
    > 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 :) ):[/color]

    thanks a lot.
    Can you do the same using ARP who-has request ? :)

    Comment

    • Peter Hansen

      #3
      Re: TELNET instead PING

      DCK wrote:[color=blue]
      >
      > 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 :) ):[/color]

      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

      Comment

      • Gandalf

        #4
        Re: TELNET instead PING


        Peter Hansen wrote:
        [color=blue]
        >DCK wrote:
        >
        >[color=green]
        >>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 :) ):
        >>
        >>[/color]
        >
        >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.
        >
        >[/color]
        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.


        Comment

        • Peter Hansen

          #5
          Re: TELNET instead PING

          > Gandalf wrote:[color=blue]
          >
          > I think there is no universal way to determine if a remote host is alive or not.[/color]

          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

          Comment

          • Serge A. Ribalchenko

            #6
            Re: TELNET instead PING

            Gandalf wrote:

            [color=blue]
            > 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.[/color]

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


            Comment

            • Gandalf

              #7
              Re: TELNET instead PING

              >[color=blue][color=green]
              >> 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.[/color]
              >
              >
              > If we are talking about IP network segment in the same ethernet layer,
              > can you ignore my ARP request - who-has <your-ip> ?
              >[/color]
              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.


              Comment

              • DCK

                #8
                Re: TELNET instead PING

                Peter Hansen wrote:[color=blue]
                > 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.[/color]
                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.
                [color=blue]
                > 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'[/color]

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

                Greetz
                Michal DCK Kaczor

                Comment

                • Kirk Strauser

                  #9
                  Re: TELNET instead PING

                  -----BEGIN PGP SIGNED MESSAGE-----
                  Hash: SHA1

                  At 2004-01-27T11:11:22Z, "DCK" <dck@gazeta.p l> writes:
                  [color=blue]
                  > I was on some kind of Network course, where teacher said, that telnet is
                  > better then PING.[/color]

                  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.

                  -----BEGIN PGP SIGNATURE-----
                  Version: GnuPG v1.2.4 (GNU/Linux)

                  iD8DBQFAFn/T5sRg+Y0CpvERAq 0UAJ9WhPxMY1Um9 3QwcOLqGHy+0Klc QgCeJbdW
                  4o7kvcO5ryEZ8Hr SwDy7o9c=
                  =kPeN
                  -----END PGP SIGNATURE-----

                  Comment

                  Working...