Jump to content
Sign in to follow this  

IP 2 Country

Recommended Posts


It's a PHP script that checks a MySQL database for information regarding an IP address:

• Country

• Registrar

• Registration time stamp (converted to date / time by the PHP script)

I guess I mainly made this for three reasons:

• If I wanted to easily detect which country an IP address belonged to.

• If I wanted to reject access from a specific country to my website.

• If I added multiple-language support to a website, based on the country.

If you want to check it out, the site is [HERE].

Get the PHP scripts and MySQL export [HERE].

Credit for the country information that is in the database goes to this website.

How did I put that into MySQL?

1) Downloaded the CSV and export it as a tab-delimited *.TXT file.

2) Make an AutoIt script that reads the TXT file line-by-line and adds the rest of the stuff for the MySQL INSERT statements, saving line-by-line to an SQL file.

3) Import the SQL file into a database.

4) Configure the config.php file that I made with the proper MySQL credentials.

5) Put both PHP files into your website's directory (or a sub-folder thereof).

6) Let her rip!

Note: You can also link to a look-up by adding ?ip=(ip address) to the end of the URL. Example

For anyone wanting it, here is the script I made to make the MySQL file.

HotKeySet('{numpadadd}', 'show')
HotKeySet('{numpadsub}', 'close')

$in = 'Input2.txt'
$out = 'Output2.sql'
$table = 'ThisTable'
$min = 1
$max = 104600
$show = 1

Global $logger[10]


ConsoleWrite('Start :   ' & curTime() & @CRLF)

FileWrite($out, 'TRUNCATE `' & $table & '`;' & @CRLF)

For $i = $min To $max
    If StringRight($i, 1) = 0 Then
        If $show = 1 Then
            ToolTip($i-($min-1) & '/' & $max-$min & @CRLF & Round(100*(($i-($min-1))/($max-$min)), 2) & '%', 0, 0, 'Progress')
    For $j = 0 To 9
        If $logger[$j] <> 1 Then
            If Round(100*(($i-($min-1))/($max-$min)), 0) = ($j+1)*10 Then
                If ($j+1)*10 < 100 Then ConsoleWrite(' ')
                ConsoleWrite('%  :  ' & curTime() & @CRLF)
                $logger[$j] = 1

    $read = FileReadLine($in, $i)
    $read = StringSplit($read, '    ')
    FileWrite($out, 'INSERT INTO `' & $table & '` VALUES (')
    For $k = 1 To 7
        $ch = '"'
        If $k = 1 Or $k = 2 Or $k = 4 Then $ch = ''
        $en = ', '
        If $k = 7 Then $en = ''
        FileWrite($out, $ch & $read[$k] & $ch & $en)
    FileWrite($out, ');' & @CRLF)

Func curTime()
    Return @HOUR & ':' & @MIN & ':' & @SEC; & ':' & @MSEC

Func show()
    $show *= -1
    If $show = -1 Then

Func close()

Comments are welcome. ;)

Take care, and enjoy!

Edited by cembry90

AutoIt Stuff:


UDFs: {Grow}

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.