#!/usr/bin/perl
WhoisKR($ARGV[0]);
sub WhoisKR
{
my($ip) = @_;
my($org);
my($addr);
my($city);
my($name);
my($tel);
my($email);
my($orgflag) = 1;
my($addrflag) = 1;
my($cityflag) = 1;
my($nameflag) = 1;
my($telflag) = 1;
my($emailflag) = 1;
@result = `whois -h whois.nic.or.kr $ip`;
foreach (@result)
{
chomp($_);
if(/^Above domain name is not registered to KRNIC./ || /No match/ || /http:\/\/www.apnic.net/)
{
WhoisAPNIC($ip);
return;
}
}
foreach (@result)
{
if(/^기관명/ && $orgflag)
{
chomp($_);
@field = split(': ', $_);
$field[1] =~ s/\ +//;
$org = $field[1];
$orgflag = 0;
}
if(/^시도명/ && $cityflag)
{
chomp($_);
@field = split(': ', $_);
$field[1] =~ s/\ +//;
$city = $field[1];
$cityflag = 0;
}
if(/^주소/ && $addrflag)
{
chomp($_);
@field = split(': ', $_);
$field[1] =~ s/\ +//;
$addr = $field[1];
$addrflag = 0;
}
if(/^이름/ && $nameflag)
{
chomp($_);
@field = split(': ', $_);
$field[1] =~ s/\ +//;
$name = $field[1];
$nameflag = 0;
}
if(/^전화 번호/ && $telflag)
{
chomp($_);
@field = split(': ', $_);
$field[1] =~ s/\ +//;
$tel = $field[1];
$telflag = 0;
}
if(/^전자 우편/ && $emailflag)
{
chomp($_);
@field = split(': ', $_);
$field[1] =~ s/\ +//;
$email = $field[1];
$emailflag = 0;
last;
}
if(/고객에게 할당되지 않은/)
{
print("$ip : 할당되지 않은 IP 주소\n");
return;
}
}
print("$ip : $org - $city $addr [$name : $tel / $email]\n");
}
sub WhoisAPNIC
{
my($ip) = @_;
my($person);
my($address);
my($country);
my($phone);
my($email);
@result = `whois -h whois.apnic.net $ip`;
foreach (@result)
{
chomp($_);
if(/ERROR/ || /Not allocated/)
{
WhoisARIN($ip);
return;
}
}
foreach (@result)
{
if(/^person/)
{
chomp($_);
@field = split(': ', $_);
$field[1] =~ s/\ +//;
$person = $field[1];
}
if(/^address/)
{
chomp($_);
@field = split(': ', $_);
$field[1] =~ s/\ +//;
$address = $field[1];
}
if(/^country/)
{
chomp($_);
@field = split(': ', $_);
$field[1] =~ s/\ +//;
$country = $field[1];
}
if(/^phone/)
{
chomp($_);
@field = split(': ', $_);
$field[1] =~ s/\ +//;
$phone = $field[1];
}
if(/^e-mail/)
{
chomp($_);
@field = split(': ', $_);
$field[1] =~ s/\ +//;
$email = $field[1];
}
}
print("$ip : $address, $country [$person : $phone / $email]\n");
}
sub WhoisARIN
{
my($ip) = @_;
my($orgname);
my($city);
my($country);
my($stateprov);
my($techname);
my($techemail);
my($techphone);
my($orgnameflag) = 1;
my($cityflag) = 1;
my($countryflag) = 1;
my($stateprovflag) = 1;
my($technameflag) = 1;
my($techemailflag) = 1;
my($techphoneflag) = 1;
my($name);
@result = `whois -h ws.arin.net $ip`;
foreach (@result)
{
chomp($_);
if(/^No match/)
{
print("NO MATCH [$ip]\n");
}
}
foreach (@result)
{
if(/\ \(/)
{
$name = $`;
}
if(/^OrgName/ && $orgnameflag)
{
chomp($_);
@field = split(': ', $_);
$field[1] =~ s/\ +//;
$orgname = $field[1];
$orgnameflag = 0;
}
if(/^City/ && $cityflag)
{
chomp($_);
@field = split(': ', $_);
$field[1] =~ s/\ +//;
$city = $field[1];
$cityflag = 0;
}
if(/^Country/ && $countryflag)
{
chomp($_);
@field = split(': ', $_);
$field[1] =~ s/\ +//;
$country = $field[1];
$countryflag = 0;
}
if(/^StateProv/ && $stateprovflag)
{
chomp($_);
@field = split(': ', $_);
$field[1] =~ s/\ +//;
$stateprov = $field[1];
$stateprovflag = 0;
}
if(/^TechName/ && $technameflag)
{
chomp($_);
@field = split(': ', $_);
$field[1] =~ s/\ +//;
$techname = $field[1];
$technameflag = 0;
}
if(/^TechPhone/ && $techphoneflag)
{
chomp($_);
@field = split(': ', $_);
$field[1] =~ s/\ +//;
$techphone = $field[1];
$techphoneflag = 0;
}
if(/^TechEmail/ && $techemailflag)
{
chomp($_);
@field = split(': ', $_);
$field[1] =~ s/\ +//;
$techemail = $field[1];
$techemailflag = 0;
}
}
if($orgname ne "")
{
print("$ip : $orgname, $city, $stateprov, $country [$techname: $techphone / $techemail]\n");
}
else
{
print("$ip : $name\n");
}
}
카페 게시글
프로그램관련
펄로만든 후이즈 검색
김철민
추천 0
조회 23
03.08.22 17:29
댓글 0
다음검색