如何從主機名稱找到該domain
從perlmonks.org找到:
http://perlmonks.org/?node_id=44456
Extracting domain names from FQDNs
sub parse_fqdn {
my $fqdn = shift;
my @tlds = (
[qw(com net org)], # common
[qw(gov edu co\.uk co\.jp gov\.tw edu\.tw com\.tw)], # not-so-common
[qw(la li it po)] # downright odd (long list)
);
foreach my $level (@tlds) {
#warn "pass ". ++$pass;
for(@{$level}) {
return $1 if $fqdn =~ /\.(\w+?\.$_)$/;
}
}
warn "unable to find domain from $fqdn\n";
return $fqdn;
}
my $domain = parse_fqdn("$ARGV[0]");
print "$ARGV[0] => $domain\n";
http://perlmonks.org/?node_id=44456
Extracting domain names from FQDNs
sub parse_fqdn {
my $fqdn = shift;
my @tlds = (
[qw(com net org)], # common
[qw(gov edu co\.uk co\.jp gov\.tw edu\.tw com\.tw)], # not-so-common
[qw(la li it po)] # downright odd (long list)
);
foreach my $level (@tlds) {
#warn "pass ". ++$pass;
for(@{$level}) {
return $1 if $fqdn =~ /\.(\w+?\.$_)$/;
}
}
warn "unable to find domain from $fqdn\n";
return $fqdn;
}
my $domain = parse_fqdn("$ARGV[0]");
print "$ARGV[0] => $domain\n";
<< Home