Find the answer to your Linux question:
Results 1 to 3 of 3
ok so i want to be able to run telnet as such : telnet <ip> <port> and then when it hangs and says "escape character '^']." i want it to ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Jan 2004
    Posts
    1

    telnet script help!!!


    ok so i want to be able to run telnet as such : telnet <ip> <port> and then when it hangs and says "escape character '^']." i want it to do a "get /http/1.0". creating a process in java isnt working cause its hanging waiting for user input before ending the process. then i tried to write a perl script and it does the same thing. i know there has to be a way to do this but am unsure how. any help would be much appreciated.

  2. #2
    Just Joined!
    Join Date
    Nov 2002
    Location
    USA
    Posts
    99
    What is "/http/1.0"? Are you just referring to the http 1.0 protocol or is that a URI?
    Anyway, sounds like from your post that you are trying to telnet to a webserver and you want to automate it. If that is the case, then you are probably better off using an http client library in whatever scripting language that you use to implement the script.

    I'm not sure what the library for perl is, but here's how to do it in python:
    Change "hostname" to the name of the host you want to connect to.
    And change "index.html" to the URI that you are searching for.

    Code:
    #!/usr/bin/env python
    
    import httplib
    
    conn = httplib.HTTPConnection&#40;"hostname"&#41;
    conn.request&#40;"GET", "/index.html"&#41;
    r = conn.getresponse&#40;&#41;
    print r.status, r.reason
    data = r.read&#40;&#41;
    print data
    conn.close&#40;&#41;

  3. #3
    Linux Guru
    Join Date
    Oct 2001
    Location
    Täby, Sweden
    Posts
    7,578
    In bash, you can either use netcat, or do this:
    Code:
    exec 3<>/dev/tcp/hostname/80
    
    cat >&3 <<EOF
    GET / HTTP/1.0
    Host&#58; hostname
    
    EOF
    
    cat <&3
    exec 3<&-
    In any case, don't use telnet. It was never meant to be used like that.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •