cosmicperl has asked for the wisdom of the Perl Monks concerning the following question:

Hi All,
  I'm sure this is an easy one to those in the know. Basically I want to code a script that checks a remote webserver by domain name and returns what data it can. I've seen scripts doing this such as:-
http://whois.domaintools.com/cosmicperl.com
I know how to grab the page with LWP, and I could figure out how to get the DMOZ listings, etc. But what I have no clue about is the "Server Data" section, which for the example site contains:-
Server Data
Server Type: Apache/2.0.54 (Fedora)
IP Address: 213.133.65.182
IP Location United Kingdom - United Kingdom - Netsight Internet Solutions Ltd
Response Code: 200
Blacklist Status: Clear
SSL Cert: localhost.localdomain SSL Certificate has expired.
Domain Status: Registered And Active Website

I know it's GeoIP for the IP location, but how is it telling the server type? SSL cert? And forgive me for being stupid but right now I can't remember how to get an IP from a domain name.

Thanks in advance

Replies are listed 'Best First'.
Re: Getting Remote server info??
by shmem (Chancellor) on Jun 11, 2007 at 04:44 UTC
    I know it's GeoIP for the IP location, but how is it telling the server type?

    It just does a HTTP "GET /" request to that domain's webserver and looks into the response header, e.g what you get with a HEAD request:

    perl -e 'use LWP::UserAgent; print LWP::UserAgent->new()->head("http:/ +/cosmicperl.com")->headers()->as_string' Connection: close Date: Mon, 11 Jun 2007 02:53:48 GMT Accept-Ranges: bytes Server: Apache/2.0.54 (Fedora) Vary: Accept-Encoding Content-Type: text/html; charset=ISO-8859-1 Client-Date: Mon, 11 Jun 2007 04:23:12 GMT Client-Peer: 213.133.65.182:80 Client-Response-Num: 1

    More information is available if you exchange the head() with get() in the above one-liner. For the cert, it sends a HTTPS request and looks into what certificate is being sent; then the scripts asks some RBL database, etc.

    And forgive me for being stupid but right now I can't remember how to get an IP from a domain name
    See Socket, e.g.
    perl -MSocket -le 'print inet_ntoa(inet_aton("cosmicperl.com"))' 213.133.65.182

    --shmem

    _($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                                  /\_¯/(q    /
    ----------------------------  \__(m.====·.(_("always off the crowd"))."·
    ");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}
Re: Getting Remote server info??
by kunwon1 (Sexton) on Jun 11, 2007 at 04:47 UTC

    Server Type and response code are part of the headers the webserver returns for every http request it receives. These can easily be obtained from the HTTP response object, see the LWP docs for details.

    Blacklist Status is probably obtained by querying an external service. There are lots of blacklists for various purposes, perhaps most notably spam blacklists e.g. Spamhaus. There are Perl modules available for querying such services, search CPAN.

    As for the rest, nothing jumps immediately to mind, although it shouldn't be that hard to find.