Sign in to follow this  
Followers 0
cembry90

IP 2 Country

1 post in this topic

#1 ·  Posted (edited)

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]

FileDelete($out)

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')
        EndIf
    EndIf
    For $j = 0 To 9
        If $logger[$j] <> 1 Then
            If Round(100*(($i-($min-1))/($max-$min)), 0) = ($j+1)*10 Then
                ConsoleWrite(($j+1)*10)
                If ($j+1)*10 < 100 Then ConsoleWrite(' ')
                ConsoleWrite('%  :  ' & curTime() & @CRLF)
                $logger[$j] = 1
            EndIf
        EndIf
    Next

    $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)
    Next
    FileWrite($out, ');' & @CRLF)
Next

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

Func show()
    $show *= -1
    If $show = -1 Then
        ToolTip('')
    EndIf
EndFunc

Func close()
    Exit
EndFunc
[/quote]

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  
Followers 0