ipv6 => { default => 'whois.6bone.net' },
);
+my $ipv4_rx = qr/[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}/;
+my $ipv6_rx = qr/[0-9:]+/;
+
sub whois {
my ($host, $callback, $args) = @_;
return unless $host and $callback;
my $server;
- if ($host =~ /^\s*\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}(\/\d{1,2})?$/) {
+ if ($host =~ /^\s*($ipv4_rx)(?:\/[0-9]{1,2})?[\s\.]*$/o) {
+ $host = $1;
$server = $whois_servers{ipv4}{default};
- } elsif ($host =~ /^\s*[\d:]*(\/\d{1,2})?\s*$/) {
+ } elsif ($host =~ /^\s*($ipv6_rx)(?:\/[0-9]{1,2})?[\s\.]*$/o) {
+ $host = $1;
$server = $whois_servers{ipv6}{default};
- } elsif ($host =~ /([^\.]+)\.+([a-z]+)\.*$/) {
+ } elsif ($host =~ /([^\.]+)\.+([a-z]+)[\.\s]*$/) {
$host = $1 . '.' . $2;
$server = $whois_servers{domain}{$2};
$server = $whois_servers{domain}{default} unless $server;