'Script that will print HTTP headers for multiple servers
I've created the following bash script:
#!/bin/bash
for ip in $(cat targets.txt); do
"curl -I -k https://"${ip};
"curl -I http://"${ip}
done
However I am not receiving the expected output, which is the HTTP header responses from IP addresses listed in targets.txt
I'm not sure how curl can attempt both HTTP and HTTPS (80/443) within one command, so I've set two seperate curl commands.
Solution 1:[1]
nmap
might be more appropriate for the task: nmap -iL targets.txt -p T:80,443 -sV --script=banner --open
Perform a network map (nmap
) of hosts from the input list (-iL targets.txt
) on TCP ports 80 and 443 (-p T:80,443
) with service/version detection (-sV
) and use the banner grabber script (--script=banner
, ref. https://nmap.org/nsedoc/scripts/banner.html). Return results for open ports (--open
).
... or masscan
(ref. https://github.com/robertdavidgraham/masscan): masscan $(cat targets.txt) -p 80,443 --banners
Mass scan (masscan
) all targets on ports 80 and 443 (-p 80,443
) and grab banners (--banners
).
Solution 2:[2]
Remove the quotes around your curl commands. You also don't need the ;
after the first curl.
#!/bin/bash
for ip in $(cat targets.txt); do
curl -I -k https://${ip}
curl -I http://${ip}
done
Solution 3:[3]
I added some echo
's to @John's answer to be able to have a better visibility of the results of the curl
executions. Also added port 8080 in case of proxy.
#!/bin/bash
for ip in $(cat $1); do
echo "> Webserver Port Scan on IP ${ip}."
echo "Attempting IP ${ip} on port 443..."
curl -I -k https://${ip}
echo "Attempting IP ${ip} on port 80..."
curl -I http://${ip}
echo "Attempting IP ${ip} on port 8080..."
curl -I http://${ip}:8080
done
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | masseyb |
Solution 2 | John |
Solution 3 | mkmnstr |