Ubuntu: Why I Can't Run The Script Against Localhost?



Question:

I have script which reads from method file :

OPTIONS  

and checks whether the OPTIONS is allowed on a particular site. The script is :

#!/bin/bash  #  #  if [ ! $# == 1 ]  then          echo "Usage: $0 [ URL ]"          exit 1  fi    cat method | while read LINE                  do                  cat << __eof > header  $LINE / HTTP/1.1  Host:$1      __eof  nc $1 80 < header  done  

So I can run this test against google.com and other sites. But when I run against localhost:8080 I get an error :

nc: getaddrinfo: Name or service not known  

I'm very new to scripting. Can anyone help me out?


Solution:1

I don't think it is a problem of scripting but your syntax at the nc command.

nc syntax is: nc -l -p port [-options] [hostname] [port] See man nc for further info.

When using the nc command, hostname is followed by port(s) separated by blank(s). If you call your script with parameter localhost:8080 the shell will not translate this so the port will be regarded as part of the hostname.


Solution:2

To fix this add the following to your /etc/hosts, if it is not already there which is on most if not all ubuntu releases:

'127.0.0.1 localhost'

However I agree with Jens. It seems your syntax is incorrect. Yuu say you run it against localhost:8080 however in your script port 80 is hard coded, meaning you actualy say port 80 on host localhost:8080 and of course that host does not exist.

Kind regards,
Jochen


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »