command line tcp/ip connection problems in netcat

Asked by Peter M O Gardner

Hi, im trying to get the folllowing netcat code to work... $ echo -n "GET / HTTP/1.0\r\n\r\n" | nc host.example.com 80
i am trying to test it for connections so i can get gawk to do the same, ( which it doesnt atm )

any ideas?

many thanks,

Pete

Question information

Language:
English Edit question
Status:
Solved
For:
Ubuntu gnome-terminal Edit question
Assignee:
No assignee Edit question
Solved by:
Michael Wood
Solved:
Last query:
Last reply:
Revision history for this message
Best Michael Wood (mwood) said :
#1

You need "echo -e" to output <CR><LF> instead of \\r\\n

$ echo "XXX\r\nXXX"
XXX\r\nXXX
$ echo -e "XXX\r\nXXX"
XXX
XXX

so:

echo -en "GET / HTTP/1.0\r\n\r\n" | nc host.example.com 80

Revision history for this message
Peter M O Gardner (pmoeg) said :
#2

Thanks Mr wood, i wonder if you can then help me with these gawk scripts that download the links from a given website as i have been struggling...:

code: gawk -f geturl.awk http://www.simplycigars.co.uk/index.php/ | gawk -f webgrab.awk | sh

and the script; geturl.awk

------------------------------------------------------

BEGIN {
  if (ARGC != 2) {
    print "GETURL - retrieve Web page via HTTP 1.0"
    print "IN:\n the URL as a command-line parameter"
    print "PARAM(S):\n -v Proxy=MyProxy"
    print "OUT:\n the page content on stdout"
    print " the page header on stderr"
    print "JK 16.05.1997"
    print "ADR 13.08.2000"
    exit
  }
  URL = ARGV[1]; ARGV[1] = ""
  if (Proxy == "") Proxy = "127.0.0.1"
  if (ProxyPort == 0) ProxyPort = 80
  if (Method == "") Method = "GET"
  HttpService = "/inet/tcp/0/" Proxy "/" ProxyPort
  ORS = RS = "\r\n\r\n"
  print Method " " URL " HTTP/1.0" |& HttpService
  HttpService |& getline Header
  print Header > "/dev/stderr"
  while ((HttpService |& getline) > 0)
    printf "%s", $0
  close(HttpService)
}

----------------------------------------------------

and the script;webgrab.awk

---------------------------------------------------

BEGIN { RS = "http://[#%&\\+\\-\\./0-9\\:;\\?A-Z_a-z\\~]*" }
RT != "" {
   command = ("gawk -v Proxy=MyProxy -f geturl.awk " RT \
               " > doc" NR ".html")
   print command
}

---------------------------------------------------