you can use the WHOIS service provider like lacnic or arin.
Here my php implementation
snip
This code wouldn't work straight off; the function
QueryWhoisServer does not exist during the call.
Not only this, but IMO it's a lot more complicated than it needs to be. Something like this may be easier:
<?php
$bannedHosts = array('example-host.com', 'example-host-2.net');
//See [1]
$userIP = $_SERVER['REMOTE_ADDR'];
//See [2]
//Get the NastyHosts response
$nastyHostsResponse = json_decode(file_get_contents('http://v1.nastyhosts.com/' . $userIP));
//Now check if the hostname is in the array
foreach($bannedHosts as $host){
if(strpos($nastyHostsResponse, $host) !== false){
//Something has been found
die('Banned Hostname.');
}
}
?>
This allows you to put in partial hostnames and for them to be blocked, for example it would return positive if the user's hostname was
ec2-52-30-0-1.eu-west-1.compute.amazonaws.com provided that
compute.amazonaws.com was in the
$bannedHosts array. This obviously has the possibility to go wrong with certain hostnames, so may not be the best option if you are using a number of unspecific hosts in the
$bannedHosts array.
[1] This could either be an array, or it could read from a text file by replacing
array(...); with
file('path/to/file.txt');. This should have the same affect when running the code.
[2] This line could be replaced with any other method to get the user's IP address, since
REMOTE_ADDR can sometimes fail. If using the FaucetInABox script for example, I believe the
getIp(); function could be used. However, if using the FaucetInABox script the above code serves no purpose; this feature is already implemented into the script.
anyone knows if nastyhosts is working or not?
I'm trying to put ISP names by this service and I think this it's not working.. don't know if I do something wrong or the service is down..
Thanks!
I believe NastyHosts is working fine. If you post the code you're using here you could compare it with the above code, or I could try to help you with it.