I'm trying to prevent non-US IP addresses from creating an account. They can view the site all they want, they just can't do anything unless I whitelist them.
In Perl, I was using:
use Net::Whois::IP qw(whoisip_query);
my $response = whoisip_query($ENV{'REMOTE_ADDR'});
$orgname = $response->{'OrgName'};
if (!$orgname) { $orgname = $response->{'NetName'}; }
if ($orgname =~ /asia|africa|latin|singlehop|ripe/i) {
$foreign = 1;
}
That wasn't quite perfect, but it worked OK.
Now I'm rebuilding the script in PHP, but I can't figure out how to fetch "OrgName" or "NetName". I found
gethostbyaddr(), but that doesn't give me what I need.
I found this overly-complicated script from 5 years ago:
[
binarytides.com...]
Is there a better / faster / easier way to get the info I need? Or, more accurately, to find whether the user is not within the US? My backup is to block by a list of "known" non-US IP addresses, but I'm not sure how reliable that really is.