YMLib Systems Librarian

一些設定的記錄

我的相片
名稱:
位置: WuGu, Taipei, Taiwan

我是個大光頭,因我的頭型適合這一型。I have a perfect head style.

星期三, 9月 27, 2006

如何從主機名稱找到該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";

標籤: ,