#!/usr/bin/perl
use strict;

# this is a quick hack to count how many servers are behind
# sitefinder.verisign.com.  -nick

use Net::HTTP;

use vars qw( %map $tq );
$| = 1;
$SIG{INT} = \&got_sig_int;

while (1) {
	my $s = Net::HTTP->new(Host => 'sitefinder.verisign.com') || die $@;
	$tq++;
	$s->write_request(GET => "/index.jsp", 'User-Agent' => "Mozilla/5.0");
	my($code, $mess, %headers) = $s->read_response_headers;

	my $host;
	if($code eq 200) {
		while($s->read_entity_body(my $buf, 65535)) {
			if ($buf =~ m/This Page is generated by (.*)--/) {
				$host = $1;
				last;
			}
		}
		if ($host =~ m/(.+)-(.+)/) {
			if (defined $map{$2}{$1}) {
				print ".";
			} else {
				$map{$2}{$1} = 0;
				print "+";
			}
			$map{$2}{$1}++;
		} else {
			print "\nSERVER NAME STRING NOT FOUND\n";
		}
	} else {
		print "\nHTTP ERROR $code $mess\n";
	}
}

sub got_sig_int {
	print "\n\n";
	foreach my $loc (sort keys %map) {
		print "*** $loc\n";
		my $min = 9999;
		my ($max, $total);
		my $row = 1;
		foreach my $server (sort keys %{$map{$loc}}) {
			my $n = $server;
			$n =~ s/[a-z]*//ig;
			$min = $n if $n lt $min;
			$max = $n if $n gt $max;
			$total++;
			print "   \t$server: $map{$loc}{$server}";
			if ($row eq 4) {
				print "\n";
				$row = 0;
			}
			$row++;
		}
		print "\nserver range: $min <==> $max\n\n";
	}
	print "*** total queries: $tq\n";
	exit;
}
