| 1 | # Net::ParseWhois registrar parser driver | ||
| 2 | # Registrar: BulkRegister | ||
| 3 | # Version: 0.6 | ||
| 4 | # Updated: 11/28/2005 by Jeff Mercer <riffer@vaxer.net> | ||
| 5 | # Note: whois.bulkregister.com will return results in no less than at least | ||
| 6 | # FOUR variations. The layout is the same, but each format uses | ||
| 7 | # slightly different wording for domain stats, alternative | ||
| 8 | # puncutuation and other trivial differences. Presumably, this is | ||
| 9 | # some sort of anti-scraping approach, unless it's just stupidity | ||
| 10 | # on their part. | ||
| 11 | # Regardless, this necessitates using complex regex matches, even | ||
| 12 | # with which there is still the chance of sometimes missing data. | ||
| 13 | |||
| 14 | package Net::ParseWhois::Domain::Registrar::BulkRegister; | ||
| 15 | |||
| 16 | require 5.004; | ||
| 17 | use strict; | ||
| 18 | |||
| 19 | @Net::ParseWhois::Domain::Registrar::BulkRegister::ISA = qw(Net::ParseWhois::Domain::Registrar); | ||
| 20 | $Net::ParseWhois::Domain::Registrar::BulkRegister::VERSION = 0.6; | ||
| 21 | |||
| 22 | sub rdebug { 0 } | ||
| 23 | sub regex_org_start { '^$'} | ||
| 24 | sub regex_no_match { '^Not found\!' } | ||
| 25 | sub regex_created { '^Record (?:created on|created date on:|create date - |created on->) (.*)$' } | ||
| 26 | sub regex_expires { '^Record (?:expires on|will be expiring on date:|will expire on - |expiring date->) (.*)$' } | ||
| 27 | sub regex_updated { '^Record (?:updated on|updated date on:|update date - |updated on->) (.*)$' } | ||
| 28 | sub regex_domain { '^Domain Name: (.*)$' } | ||
| 29 | sub regex_nameservers { '^Domain servers in listed order:$' } | ||
| 30 | sub my_contacts { [ qw(Administrative Technical Billing) ] } | ||
| 31 | sub my_data { [ qw(my_contacts regex_org_start regex_no_match regex_created regex_expires regex_updated regex_domain regex_nameservers) ] } | ||
| 32 | |||
| 33 | sub parse_text { | ||
| 34 | my $self = shift; | ||
| 35 | my $text = shift; # array ref, one line per element | ||
| 36 | |||
| 37 | $self->dump_text($text) if $self->rdebug; | ||
| 38 | |||
| 39 | $self->parse_start($text); | ||
| 40 | $self->dump_text($text) if $self->rdebug; | ||
| 41 | $self->parse_org($text); | ||
| 42 | $self->dump_text($text) if $self->rdebug; | ||
| 43 | $self->parse_domain_name($text); | ||
| 44 | $self->dump_text($text) if $self->rdebug; | ||
| 45 | $self->parse_contacts($text); | ||
| 46 | $self->dump_text($text) if $self->rdebug; | ||
| 47 | $self->parse_domain_stats($text); | ||
| 48 | $self->dump_text($text) if $self->rdebug; | ||
| 49 | $self->parse_nameservers($text); | ||
| 50 | $self->dump_text($text) if $self->rdebug; | ||
| 51 | |||
| 52 | return $self; | ||
| 53 | } | ||
| 54 | |||
| 55 | #sub parse_start { | ||
| 56 | # my $self = shift; | ||
| 57 | # my $text = shift; | ||
| 58 | # | ||
| 59 | # my $t = shift @{ $text }; | ||
| 60 | # if (!defined $t || $t =~ /$self->{'regex_no_match'}/) { | ||
| 61 | # $self->{'MATCH'} = 0; | ||
| 62 | # } else { | ||
| 63 | # $self->{'MATCH'} = 1; | ||
| 64 | # if ($t =~ /^(.*)$/) { | ||
| 65 | # $self->{'NAME'} = $1; | ||
| 66 | # if ($self->{'NAME'} =~ /^(.*)\s+\((\S+)\)$/) { | ||
| 67 | # $self->{'NAME'} = $1; | ||
| 68 | # $self->{'TAG'} = $2; | ||
| 69 | # } | ||
| 70 | # } else { | ||
| 71 | # die "Registrant Name not found in returned information\n"; | ||
| 72 | # } | ||
| 73 | # } | ||
| 74 | #} | ||
| 75 | |||
| 76 | |||
| 77 | # Replace parse_contacts method from parent Registrar class. Mainly just | ||
| 78 | # to deal with alternate regex for matching Contact header lines | ||
| 79 | sub parse_contacts { | ||
| 80 | # Initialization | ||
| 81 | my ($self, $text) = @_; | ||
| 82 | my ($done, $t, $blah, $ck); | ||
| 83 | my (@ctypes, @c); | ||
| 84 | warn "DEBUG: parse_contacts() running\n" if $self->rdebug; | ||
| 85 | |||
| 86 | # As long as we have text to eat... | ||
| 87 | while (@{ $text }) { | ||
| 88 | # Check to see if all the contacts have been filled in | ||
| 89 | $done = 1; | ||
| 90 | foreach $ck (@{ $self->{'my_contacts'} }) { | ||
| 91 | warn "DEBUG: ck=$ck\n" if $self->rdebug; | ||
| 92 | unless ($self->{CONTACTS}->{uc($ck)}) { $done = 0; } | ||
| 93 | } | ||
| 94 | last if $done; | ||
| 95 | |||
| 96 | # Grab next line of test, skip it if blank | ||
| 97 | $t = shift(@{ $text }); | ||
| 98 | warn "DEBUG: t = $t\n" if $self->rdebug; | ||
| 99 | next if $t=~ /^$/; | ||
| 100 | |||
| 101 | |||
| 102 | # If this line is a contact header... | ||
| 103 | if ($t =~ /contact(?:::|:| - |)$/i) { | ||
| 104 | # Figure out what contact type(s) it's for | ||
| 105 | warn "DEBUG: Matched against /contact.*:/ regex\n" if $self->rdebug; | ||
| 106 | @ctypes = ($t =~ /\b(\S+) contact/ig); | ||
| 107 | @c=(); | ||
| 108 | if ($self->rdebug) { | ||
| 109 | printf "DEBUG: ctypes=%d\n", $#ctypes+1 if $self->rdebug; | ||
| 110 | foreach (@ctypes) { | ||
| 111 | warn "DEBUG: ctypes contains=$_\n"; | ||
| 112 | } | ||
| 113 | } | ||
| 114 | |||
| 115 | # Uh... Not sure what the point of this is. --jcm, 11/16/05 | ||
| 116 | if ($self->{'my_contacts_extra_line'}) { | ||
| 117 | $blah = shift(@{ $text }); | ||
| 118 | } | ||
| 119 | |||
| 120 | # Eat all the text until the next contact line and | ||
| 121 | # store it in hash | ||
| 122 | while ( ${ $text }[0] ) { | ||
| 123 | warn "DEBUG: text[0]=${$text}[0]\n" if $self->rdebug; | ||
| 124 | last if ${ $text }[0] =~ /contact.*:$/i; | ||
| 125 | push @c, shift @{ $text }; | ||
| 126 | } | ||
| 127 | |||
| 128 | # Take our contacts hash and map it to our objects | ||
| 129 | # CONTACTS hash. Only I think this is foobar... | ||
| 130 | printf "DEBUG: c=%d\n", $#c+1 if $self->rdebug; | ||
| 131 | foreach (@ctypes) { @{$self->{CONTACTS}{uc $_}}=@c; } | ||
| 132 | } | ||
| 133 | } | ||
| 134 | |||
| 135 | warn "DEBUG: parse_contacts() ending\n" if $self->rdebug; | ||
| 136 | } | ||
| 137 | |||
| 138 | 1; |