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

Greetings all- I'm working on a program that'll grab the http headers from webservers via requesting a nonexistant file. I'm still in the debugging stage in this, and am having a very odd problem.

The code:
#!/usr/bin/perl use IO::Socket; #unless (@ARGV) { die "usage: $0 URL\n" } die "Usage: $0 <subnet class> ip\n" unless(@ARGV==1); for ($b=0; $b <= 255; $b++) { for ($c=0; $c <= 255; $c++) { for ($d=0; $d <= 255; $d++) { $url = "http://$ARGV[0].$b.$c.$d/oiuert.tct"; #$url = "http://12.101.189.130/p.tttt"; $EOL = "\015\012"; $BLANK = $EOL x 2; $sep = ($url > 1) ? "-------------------\n" : +""; $host = "$ARGV[0].$b.$c.$d"; #$host = "12.101.189.130"; print "\nConnecting to: $host\n"; $remote = IO::Socket::INET->new( Proto => +"tcp", PeerAddr => +$host, PeerPort => +"http(80)", ); if ($remote ==0) {print "Cannot connect to htt +p daemon on $host\n" } else { $remote->autoflush(1); print $remote "GET $url HTTP/1.0" . $BLANK; while ( <$remote> ) { print } print "\n$sep"; close $remote;} } } }

The problem is when I statically assign the host and url values, the program runs- and when I leave it as it is, it doesn't run.

Suggestions?

Replies are listed 'Best First'.
Re: HTTP Header Scanner
by Zaxo (Archbishop) on May 17, 2002 at 01:23 UTC

    Have a look at LWP::UserAgent, HTTP::Request, and HTTP::Response. Those are some very round wheels ;-)

    Another prang for the sacred-to-sort package global $b, no strict, no warnings.

    That's a mighty wide swath you want to scan.

    After Compline,
    Zaxo

      looking into it
Re: HTTP Header Scanner
by dsheroh (Monsignor) on May 17, 2002 at 15:08 UTC
    If you're only interested in the server headers, why not just HEAD / instead of trying to GET something nonexistent?
      Because I couldnt get that to reply meaningful information from most webservers... IE- Netscapes WS.