1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

[GET] Mass GeoIP Lookup Tool + Source Code

Discussion in 'PHP & Perl' started by tacopalypse, Sep 24, 2012.

  1. tacopalypse

    tacopalypse Executive VIP Jr. VIP Premium Member

    Joined:
    Nov 30, 2009
    Messages:
    980
    Likes Received:
    2,487
    Home Page:
    Good morning everyone \o/

    here i've made a tool for easily auditing location data from large lists of IP addresses

    to use it, just copy any block of text containing ip addresses, and paste it into the input box

    it'll strip out the IPs from the rest of the garbage, and then draw a table with geoIP data for each IP, along with links to a map and additional whois data


    [​IMG]




    some stuff you can use this for:
    (just off the top of my head)

    checking locations of large lists of proxies
    copy IP lists from prosper 202 or other stat trackers to see where your individual visitors are coming from
    copy IPs from site access logs to see where each individual page view is coming from
    plenty of other junk i haven't thought of ;D


    here's how to install it:

    download & unpack the maxmind geoIP lite database
    Code:
    http://www.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz
    download & unpack the php api for the database (you only need 3 of the files)
    Code:
    http://www.maxmind.com/download/geoip/api/php/php-1.11.tar.gz
    save the index.php interface file from this post

    index.php:
    Code:
    <html>
    <head>
    <title>GeoIP Lookup Tool</title>
    
     <style type="text/css">
    .c1{
        font-family: courier new;
        font-size: 12;
    }
    .c2{
        font-family: arial;
        font-size: 9;
    }
    a{
        text-decoration: none;
    }
    a:hover{
        text-decoration: underline;
    }
    table{
        border: 1px outset gray;
    }
    tr:hover{
        background: #F0F0F0;
    }
    td{
        font-family: courier new;
        font-size: 11;
        border-right: 1px solid #AAAAAA;
        border-bottom: 1px solid #AAAAAA;
    }
    </style>
    
    </head>
    
    <body class="c1">
    
     <?php
    
    include("geoipcity.inc");
    include("geoipregionvars.php");
    
    function info($ip, $n)
    {
        global $gi;
        $record = geoip_record_by_addr($gi, $ip);
        $sep = " </td><td>";
    
        echo "<tr><td>";
    
        echo $n . $sep;
        echo $ip . $sep;
        echo $record->country_code . " " . $record->country_name . $sep;
        echo $record->region . " " . $GEOIP_REGION_NAME[$record->country_code][$record->region] . $sep;
        echo $record->city . $sep;
        echo $record->postal_code . $sep;
        echo $record->latitude . $sep;
        echo $record->longitude . $sep;
        echo $record->metro_code . $sep;
        echo $record->area_code . $sep;
        echo $record->continent_code . $sep;
    
        echo '<a target="_blank" href="http://whatismyipaddress.com/ip/' . $ip . '#Geolocation-Map">Map</a>' . " ";
        echo '<a target="_blank" href="http://whois.arin.net/rest/nets;q=' . $ip . '?showDetails=true&showARIN=false&ext=netref2">ARIN</a>' . " ";
        echo '<a target="_blank" href="http://www.db.ripe.net/whois?searchtext=' . $ip . '">RIPE</a>';
    
        echo "</td></tr>\r\n";
    }
    
    $q = htmlspecialchars($_POST['q']);
    
    if(!empty($q))
    {
        $gi = geoip_open("GeoLiteCity.dat",GEOIP_STANDARD);
    
        echo '<table cellspacing="0" cellpadding="4">';
        echo "<tr><td>#</td><td>IP</td><td>Country</td><td>Region</td><td>City</td><td>Zip</td><td>Latitude</td><td>Longitude</td><td>Metro</td><td>Area</td><td>Cont</td><td>More Info</td></tr>";
    
        preg_match_all("([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})", $q, $a, PREG_PATTERN_ORDER);
    
        for ($i = 0; $i < count($a[0]) ; $i++)
        {
            info($a[0][$i], $i);
        }
    
        echo "</table>";
    
        geoip_close($gi);
    }
    
    ?>
    
    <br />
    
    <form action="" method="post" >
    Lookup: <br />
    <textarea class="c1" name="q" rows="3" cols="30"></textarea> <br />
    <input type = "submit" value = "Submit" class="c1" />
    </form>
    
    <br /><br />
    
    <div class="c2">
    GeoLite databases are licensed under a <a rel="license" href="http://creativecommons.org/licenses/by-sa/3.0/">Creative Commons Attribution-ShareAlike 3.0 Unported License</a>. <br />
    This product includes GeoLite data created by MaxMind, available from <a href="http://www.maxmind.com">http://www.maxmind.com</a>
    </div>
    <br />
    
    </body>
    
    </html>
    
    

    extract the archives, and put these 5 files into the same folder. name it something simple, like "geoip"

    Code:
    GeoLiteCity.dat
    geoip.inc
    geoipcity.inc
    geoipregionvars.php
    index.php
    
    upload the folder to your website, and start it up with index.php

    try it out and feel free to modify it for your own stuff :)
    enjoy!
     
    • Thanks Thanks x 7
  2. audhora

    audhora Regular Member

    Joined:
    Apr 3, 2011
    Messages:
    218
    Likes Received:
    152
    Location:
    Bangladesh
    It's a great tool - OP. Thanks very much for saving the time :)
     
  3. futurestunner

    futurestunner BANNED BANNED

    Joined:
    Dec 26, 2009
    Messages:
    1,532
    Likes Received:
    1,036
    exactly what i was looking from day. :eek: