you're reading...
Social Graphing, Tools

IP to Street Address

IP to Street Address PHP Script

Retrieving the user’s IP address is actually much simpler than you might think, and can be done in a single line. Getenv(“REMOTE_ADDR”) will return the IP address of the person visiting your site. Generally this is accurate, however if the user is running through a proxy server, then it will return the address of the proxy.

In this example, we retrieve the user’s IP, latitude, and longitude, and then correlate it with a google maps instance.

Use the PHP script below to get a street address from an IP address! This code has greater reliability in metropolitan areas.

if($_POST["ip"] != null)
    echo "<tr><td colspan=\"2\">Nearest Street Address: ";
    $NetGeoHTML = file_get_contents("http://geocoder.ca/?moreinfo=1&latt=".$tags[latitude]."&longt=".$tags[longitude]."&range=&reverse=Reverse+GeoCode+it%21");
    preg_match ("/This is the nearest street civic address. (.*)/i", $NetGeoHTML, $temp);
    $temp = split(',', $temp[1]);
    echo $temp[0];
    <td><?php echo $tags[country]; ?></td>
    <td><?php echo $tags[latitude]; ?></td>
    <td><?php echo $tags[longitude]; ?></td>
    <td>timezone (GMT)</td>
    <td><?php echo $tags[timezone]; ?></td>
    <td><?php echo $tags[certainty]; ?></td>
  <?php } ?>
    <td align="center" class="table-footerbg-lightgrey" colspan="2"><form action="" method="post" name="frmIPAnalysis">
        <table width="500px"  border="0" cellspacing="1" cellpadding="2">
            <td width="180" align="left" valign="top"><strong>Enter IP to Analyze</strong></td>
            <td width="300" align="left"><input name="ip" type="text" class="input-box-up" value="" size="40" />
            <td align="center" colspan="2"><input type="submit" value="" style="background:url('/images/ip_to_street_address_search.jpg') no-repeat; cursor:pointer; width: 500px; height: 73px; border: none;"></td>

About Pythorian

Exploration and Production oriented security consultant for securing IT infrastructures relating to natural resources.


No comments yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: