Saturday, May 4, 2024
 Popular · Latest · Hot · Upcoming
1
rated 0 times [  1] [ 0]  / answers: 1 / hits: 655  / 3 Years ago, mon, may 3, 2021, 10:40:09

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?


More From » 12.04

 Answers
4

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.


[#36588] Tuesday, May 4, 2021, 3 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
bearous

Total Points: 226
Total Questions: 116
Total Answers: 136

Location: Guernsey
Member since Sun, Jan 10, 2021
3 Years ago
;