Shell Function – Which Webserver Does That Site Run?
April 4th, 2008
I just read the following post Python – Script – Which Webserver Does That Site Run? by blogger Corey Goldberg.
I prefer the shell version:
$ what-http-server() { curl -s -I "http://$1" | awk -F': ' '/^Server:/ {print $2}'; }
$ what-http-server www.pylot.org
Apache/2.0.52
$ what-http-server() { curl -s -I "$@" | awk -F': ' '/^Server:/ {print $2}'; }
$ what-http-server www.pylot.org google.com bashcurescancer.com
Apache/2.0.52
gws
Apache/2.2.6 (Unix)
That works but this version is more correct:
what-http-server() { curl -s -I $(for h in "$@"; do printf "http://%s " "$h"; done) | awk -F': ' '/^Server:/ {print $2}'; }
In the version which works for multiple hosts, we are letting curl assume the protocol is HTTP. This works fine most of the time. However, there are exceptions:
If you specify URL without protocol:// prefix, curl will attempt to guess what protocol you might want. It will then default to HTTP but try other protocols based on often-used host name prefixes. For example, for host names starting with “ftp.” curl will assume you want to speak FTP. – man curl
April 6th, 2008 at 6:21 am
what-http-server() { while test “$1″ ; do exec 3/dev/tcp/$1/80; echo -e “GET / HTTP/1.0\n\n” >&3; cat <&3 | awk -F’: ‘ ‘/^Server:/ {print $2}’; shift ; done ; }
will not work on debian-based distributions
April 6th, 2008 at 6:23 am
lost some code:
exec 3 <>/dev/tcp/$1/80
April 6th, 2008 at 11:37 am
Try httprint. It’s way more reliable…
April 6th, 2008 at 12:04 pm
Andrey,
See this BASH only http client.
Mathias,
Thanks for the link. I think he was just showing a very basic identifier as there are many full fledged options out there.
Brock
April 7th, 2008 at 8:53 am
Hi!
curl in not default on some distros, so might want to use
$wget -d 2>&1 | grep Server
Bye!
April 7th, 2008 at 8:55 am
Sorry, the command should be:
$wget http://www.apache.org –spider -d 2>&1 | grep Server
Bye
April 7th, 2008 at 10:11 am
ubersoldat,
Yep, if curl is not available, then this works:
April 7th, 2008 at 10:12 am
I think I need to hack on wordpress’s input filter. It sucks for those of us trying to input stuff other than text.