how2 know country code from IP ?

how2 know country code from IP address ?

somebody spam my webboard i will ban all IPs
that come from outside my country....

we can check proxy log file if he use my country proxy.


tong111797Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ozoCommented:
use Socket;
print scalar gethostbyaddr((pack'C*',split/\./,'193.63.255.1'),AF_INET)
0
tong111797Author Commented:
thank ozo

but the domain name can't tell me where it locate.

ex: home.com

http://www.tamos.com/bin/dns.cgi?IP=207.60.48.1

How they know country code from IP ?

0
TYoungCommented:
#!/usr/bin/perl
use Socket;

# Example:
$CCode = GetCountryCode('209.162.55.34');
# $CCode is now "com" for "einstein.experts-exchange.com" (209.162.55.34)

print "Content-type: text/plain\n\n";
print "209.162.55.34 (einstein.experts-exchange.com) = $CCode";
exit;

sub GetCountryCode {
      $Address = $_[0];
      $Domain = gethostbyaddr((pack'C*',split(/\./,$Address)),AF_INET);
      @parts = split(/\./, $Domain);
      $plength = @parts;
      return @parts[$plength - 1];
}
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

TYoungCommented:
That is bad code... but it works...
0
tong111797Author Commented:
top domain is not always be country code..
0
TYoungCommented:
Then what do you mean by country code? Give examples.
0
tong111797Author Commented:
ex:

Name:    sanook.com
Address:  203.150.3.234

http://www.tamos.com/bin/dns.cgi?IP=203.150.3.234

Webhosting service segment
           Internet Thailand Company Limited
           TH (Country Code Listing)

        203.150.0.0 - 203.150.3.255


above URL can resolve and know server locate in TH ( thailand)
0
jsatterlCommented:
The information you want (shown by example) is information from ARIN and will only yield results on ip addresses that have been swipped (registered with arin).  Look up information on arin whois.  Go to www.arin.net.

You may be able to find a module on CPAN that will get return arin information, otherwise you will  need to use a url like the one you listed and parse the results.
0
ozoCommented:
use LWP::Simple;
$content = get("http://www.tamos.com/bin/dns.cgi?IP=203.150.3.234");
($CCode) = $content=~m!<b>(\w+)</b>.*Country Code Listing!;
print $CCode;
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
tong111797Author Commented:
no more solution to use whois around the globe servers.

i dunno how tamos search all the whois servers.
0
nwettersCommented:
http://search.cpan.org/author/NWETTERS/IP-Country-2.11/lib/IP/Country.pm

  use IP::Country::Fast;
  my $reg = IP::Country::Fast->new();

  # next line prints 'UK'
  print $reg->inet_atocc('212.67.197.128')   ."\n";

  # next line prints 'US'
  print $reg->inet_atocc('www.slashdot.org') ."\n";
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Perl

From novice to tech pro — start learning today.