Reverse IP lookup
As an extension to my 'referer' project I also capture the IP address of the client as they arrive at my site using
$_SERVER["REMOTE_ADDR"]
I thought it would be an interesting exercise to see if I could do a reverse lookup on the IP address to identify any A (address) records held in each case.
I found a useful and free service at ipwho.is.
Using PHP's cURL is was able to provide any IP address and return some cool data.
$id = $_POST["id"];
$ip = $_POST["ipaddress"];
$ch = curl_init('http://ipwho.is/'.$ip);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, false);
$ipwhois = json_decode(curl_exec($ch), true);
curl_close($ch);
$country = "";
$flag = "";
$city = "";
$domain = "";
if (isset($ipwhois['country']))
$country = $ipwhois['country'];
if (isset($ipwhois['flag']['emoji']))
$flag = $ipwhois['flag']['emoji'];
if (isset($ipwhois['city']))
$city = $ipwhois['city'];
if (isset($ipwhois['connection']['domain']))
$domain = $ipwhois['connection']['domain'];
echo "{ \"id\": ".$id.", \"city\": \"".$city."\", \"country\": \"".$country."\", \"flag\": \"".$flag."\", \"domain\": \"".$domain."\" }";
This was all done using an AJAX call where I used jQuery's .each() function on an arrary of IP's. The printed value is specific to my code requirement. You can see the output by doing a default search on your own IP address: ipwho.is. Neat tool. You can use it for free but there is a limit to the amount of lookups you can do each month.
Old links
- Generate SSH key pair from the command line
- Some very basic thoughts on Artificial General Intelligence
- Invaders 2095 - JavaScript game in development
- Turning coarse dirt into luscious green grass in Minecraft
- Intelligent dinosaurs?
- Thoughts on writing a DOOM movie script
- Why do we always see the same side of the moon?
- Are humans descended from apes?
- Directory traversal
- http referer not capturing the query string from search engines
- Reverse IP lookup
- JavaScript Promises
- Vintage Weight Watchers Update Log
- My illustrated children's books
- Filling my skills gap
- St. Wystan's church, Repton Derbyshire
- Updates to the Vintage Points Calculator
- Massively improving database INSERTs
- Vintage Points Calculator
- What is the difference between bcrypt and Argon2 in PHP's password_hash?
- Defender 2095 - JavaScript game in development