Monday, November 8, 2010

Retrieve Country name and code from ip address

 



In order to retrieve the country name, first we have to change the ip address into ip number. Any ip address [both ipv4 and ipv6] can be divided into 4 sub blocks. Each sub block has a different weight number. Each is powered by 256. Here comes the question.... Why to use ip number? Why cant we use ip address? The answer is IP number is being used in the database because it is efficient to search between a range of number in database. Ip number can be calculated by the given formula.

IP Number = (256^3)*w + (256^2)*x + (256)*y + z
where IP Address = w.x.y.z

For example, if IP address is "202.186.13.4", then its IP Number "3401190660" is based on the Formula.
Let us check it here.

IP Address = 202.186.13.4

So, w = 202, x = 186, y = 13 and z = 4

IP Number = 16777216*202 + 65536*186 + 256*13 + 4
                  = 3388997632 + 12189696 + 3328 + 4
                  = 3401190660

Search the IP-COUNTRY TABLE to match a unique record that has the IP number fits between From IP Number and To IP Number.

For example, IP Address "202.186.13.4" is equivalent to


IP Number "3401190660". It falls in the following range of IP number in the table because it is between the "From IP number" and the "To IP number".

From the IP range, the Country Name is Malaysia.


IP-COUNTRY TABLE
From IP Number
To IP Number
Country Code Country Name
3400892416
3400925183
HK
HONG KONG
3400925184
3400933375
TH
THAILAND
3400941568
3400949759
AU
AUSTRALIA
3400957952
3400966143
AU
AUSTRALIA
3400982528
3400990719
HK
HONG KONG
3400990720
3400998911
ID
INDONESIA
3400998912
3401003007
PH
PHILIPPINES
3401007104
3401011199
IN
INDIA
3401023488
3401056255
TH
THAILAND
3401056256
3401400319
MY
MALAYSIA
3401408512
3401416703
HK
HONG KONG
3401416704
3401420799
KR
KOREA, REPU
3401441280
3401449471
PH
PHILIPPINES
3401449472
3401515263
MY
MALAYSIA
3401531392
3401539583
IN
INDIA
3401547776
3401580543
MY
MALAYSIA
3401580544
3402629119
CN
CHINA
3402629120
3404464127
JP
JAPAN
3405774848
3406434303
AU
AUSTRALIA
3406436352
3409969151
AU
AUSTRALIA
3409969152
3410755583
TW
TAIWAN
3410755584
3410780159
AU
AUSTRALIA
3410788352
3410796543
HK
HONG KONG
3410796544
3410800639
LK
SRI LANKA
3410812928
3410821119
AU
AUSTRALIA
3410821120
3410853887
TW
TAIWAN
3410853888
3410862079
HK
HONG KONG
3410870272
3410874367
IN
INDIA
3410878464
3410886655
ID
INDONESIA
3410886656
3410887679
TW
TAIWAN
3410894848
3410898943
HK
HONG KONG
3410903040
3410911231
HK
HONG KONG
3410919424
3410927615
IN
INDIA
3410944000
3410952191
PH
PHILIPPINES
3410952192
3410960383
TW
TAIWAN
3410968576
3410984959
NZ
NEW ZEALAND
3410984960
3411017727
TW
TAIWAN
3411017728
3411018751
HK
HONG KONG
3411034112
3411051519
HK
HONG KONG
3411058688
3411062783
AU
AUSTRALIA
3411066880
3411083775
HK
HONG KONG
3411087360
3411091455
CN
CHINA
3411091456
3411095551
SG
SINGAPORE
3411099648
3411107839
MM
MYANMAR
3411116032
3411124223
IN
INDIA
3411132416
3411136511
PK
PAKISTAN
3411147776
3411149311
HK
HONG KONG
3411156992
3411161087
PH
PHILIPPINES
3411165184
3411173375
MY
MALAYSIA
3411181568
3411189759
JP
JAPAN
3411197952
3411202047
BD
BANGLADESH
3411213312
3411215359
HK
HONG KONG
3411230720
3411247103
HK
HONG KONG
3411247104
3411255295
AU
AUSTRALIA
3411278848
3411296255
HK
HONG KONG
3411312640
3411313151
HK
HONG KONG
3411329024
3411337215
PH
PHILIPPINES
3411337216
3411341311
AU
AUSTRALIA
3411345408
3411411967
HK
HONG KONG
3411435520
3411443711
IN
INDIA
3411443712
3411460095
HK
HONG KONG
3411475456
3411476479
HK
HONG KONG
3411476480
3411509247
AU
AUSTRALIA
3411509248
3411517439
PH
PHILIPPINES
3411525632
3411529727
SG
SINGAPORE
3411533824
3411543039
CN
CHINA
3411558400
3411566591
AU
AUSTRALIA
3411574784
3411582975
IN
INDIA
3411591168
3411595263
HK
HONG KONG
3411599360
3411607551
AU
AUSTRALIA
3411607552
3411608575
CN
CHINA
3411623936
3411632127
AU
AUSTRALIA
3411640320
3411648511
PK
PAKISTAN
3411656704
3411673087
AU
AUSTRALIA
3411673088
3411674111
CN
CHINA
3411689472
3411701759
IN
INDIA
3411722240
3411726335
PH
PHILIPPINES
3411730432
3411738623
HK
HONG KONG
3411738624
3411739647
CN
CHINA
3411755008
3411763199
AU
AUSTRALIA
3411771392
3411779583
HK
HONG KONG
3411795968
3411804159
AU
AUSTRALIA
3411804160
3411805183
CN
CHINA
3411820544
3411832831
SG
SINGAPORE
3411836928
3411845119
MY
MALAYSIA
3411853312
3411857407
IN
INDIA
3411861504
3411869695
AU
AUSTRALIA
3411869696
3411943423
CN
CHINA
3411951616
3411967999
LK
SRI LANKA
3411968000
3411984383
AU
AUSTRALIA
3411984384
3412000767
IN
INDIA
3412000768
3412002815
CN
CHINA
3412017152
3412025343
SG
SINGAPORE
3412033536
3412066303
TW
TAIWAN
3412066304
3412213759
NZ
NEW ZEALAND
3412213760
3412221951
AU
AUSTRALIA
3412230144
3412246527
HK
HONG KONG
3412254720
3412262911
NR
NAURU
3412262912
3412273151
NZ
NEW ZEALAND
3412279296
3412281343
NZ
NEW ZEALAND
 If anyone want to download the .sql file and compile in your database system then click here

source : HACKINDIA007

No comments:
Write comments