Archive

Archive for October 18, 2010

List the languages of each countries

October 18, 2010 Leave a comment

Below is a list of actions that I have took to extract the languages of each countries. I am sharing the procedure so If you can suggest some optimal procedure to carry out the same task.

Steps:

  1. Visit the CIA world fact book page as mentioned above
  2. Copy that html code while holds the required data using Firebug
  3. Browse the file and copy the fields using pointer
  4. Paste the fields in the text file named languages.txt
  5. Learn how to read the file line by line from php manual
  6. Apply the following PHP script to filter out the data in terms of Country and Native languages

<?php
$myfile = ‘languages.txt’;
$lines = file($myfile);
for($i=count($lines);$i>0;$i–){

$arr = explode(‘ ‘, $lines[$i], 2); // Seperate Country and Native languages
$native = $arr[1]; // Only native languages sperated by “,”
echo “<pre>”;
echo $arr[0];
print_r(explode(‘,’, $native));
echo “</pre>”;
}
?>

What’s left:
Populating the database with the above extracted data.

Categories: Web Services Tags:

IP to country conversion

October 18, 2010 1 comment

Though there are a lot of available solutions to tackle this problem but the one reside in the Google Code is the perfect one with simplicity and ease of use. Below is the work around to setup a test case; -

Explore the code:

Visit the project’s profile and read about the documentation.

Download the code;

Get the latest code from the repo and extract it to the root directory of the web server. Linux – /var/www/phpip2country Windows – C:\xampp\htdocs\phpip2country

Test the code:

Browse the directory in the browser. http://localhost/phpip2country/index.php

You need to upload the sql file which is actually a mapper for IP and Countries.

Results:

IP: 127.0.0.1
IP numerical Value: 2130706433
IP registry: IANA
IP assigned (Y-m-d H:i:s): 1983-01-01 05:00:00
IP country RIR (Regional Internet Registry) representation: ZZ
IP Country Abbreviation: ZZZ
IP country name: RESERVED
IP range: array (
‘FROM’ => ’127.0.0.0′,
‘TO’ => ’127.255.255.255′,
)
IP range numerical: array (
‘FROM’ => ’2130706432′,
‘TO’ => ’2147483647′,
)
full IP informations array: array (
‘IP_FROM’ => ’2130706432′,
‘IP_TO’ => ’2147483647′,
‘REGISTRY’ => ‘IANA’,
‘ASSIGNED’ => ’410227200′,
‘CTRY’ => ‘ZZ’,
‘CNTRY’ => ‘ZZZ’,
‘COUNTRY’ => ‘RESERVED’,
‘IP_STR’ => ’127.0.0.1′,
‘IP_VALUE’ => 2130706433,
‘IP_FROM_STR’ => ’127.0.0.0′,
‘IP_TO_STR’ => ’127.255.255.255′,
)

Below is the output when the code has been set on a live server.

IP: 116.58.42.211
IP numerical Value: 1949969107
IP registry: APNIC
IP assigned (Y-m-d H:i:s): 2007-03-27 19:00:00
IP country RIR (Regional Internet Registry) representation: PK
IP Country Abbreviation: PAK
IP country name: PAKISTAN
IP range: array (
‘FROM’ => ’116.58.0.0′,
‘TO’ => ’116.58.127.255′,
)
IP range numerical: array (
‘FROM’ => ’1949958144′,
‘TO’ => ’1949990911′,
)
full IP informations array: array (
‘IP_FROM’ => ’1949958144′,
‘IP_TO’ => ’1949990911′,
‘REGISTRY’ => ‘APNIC’,
‘ASSIGNED’ => ’1175040000′,
‘CTRY’ => ‘PK’,
‘CNTRY’ => ‘PAK’,
‘COUNTRY’ => ‘PAKISTAN’,
‘IP_STR’ => ’116.58.42.211′,
‘IP_VALUE’ => 1949969107,
‘IP_FROM_STR’ => ’116.58.0.0′,
‘IP_TO_STR’ => ’116.58.127.255′,
)

Categories: Web Tools Tags: , ,
Follow

Get every new post delivered to your Inbox.