#!/usr/bin/perl -w use strict; use LWP::UserAgent; use Test::More; use Net::Whois::Raw; { no warnings; $Net::Whois::Raw::CHECK_FAIL = 2; $Net::Whois::Raw::OMIT_MSG = 2; $Net::Whois::Raw::CHECK_EXCEED = 2; $Net::Whois::Raw::TIMEOUT = 10; } our $DEBUG = 0; our $fake_domain = "fake123domain"; my $tests_number = keys(%Net::Whois::Raw::Data::servers) * 2; if ($ARGV[0] && $ARGV[0] eq "-f") { plan tests => $tests_number; } else { plan skip_all => "Coverage tests skiped by default."; } print "The following tests requires internet connection.\n"; print "Coverage tests skiped by default. Run with -f to force.\n"; foreach my $tld (sort keys %Net::Whois::Raw::Data::servers) { SKIP: { my $server = $Net::Whois::Raw::Data::servers{$tld}; my $domain = get_domain($tld); skip( "Cant find domain in .$tld", 2 ) unless $domain; my $whois = eval { whois( $domain ) }; print "---------------\n$whois\n-------------\n" if $DEBUG; if ($@) { ok( 0, "TLD: $tld,\tdomain: $domain,\tserver: $server\t - timeout"); } else { ok( $whois, "TLD: $tld,\tdomain: $domain,\tserver: $server"); } $domain = "$fake_domain.$tld"; $whois = eval { whois( $domain ) }; if ($@) { ok( 0, "TLD: $tld,\tdomain: $domain,\tserver: $server\t - timeout"); } else { ok( !$whois, "TLD: $tld,\tdomain: $domain,\tserver: $server"); } print "\n"; } }; sub get_domain { my $tld = shift; my $content = get_google($tld); my ($domain) = $content =~ /new( GET => 'http://www.google.com.ua/search?q=site:'.$tld ); my $res = $ua->request($req); return $res->content; }