• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 453
  • Last Modified:

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.


0
tong111797
Asked:
tong111797
  • 4
  • 3
  • 2
  • +2
1 Solution
 
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
[Webinar] Kill tickets & tabs using PowerShell

Are you tired of cycling through the same browser tabs everyday to close the same repetitive tickets? In this webinar JumpCloud will show how you can leverage RESTful APIs to build your own PowerShell modules to kill tickets & tabs using the PowerShell command Invoke-RestMethod.

 
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
 
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

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 4
  • 3
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now