Today, I have nothing to do at home. I went online and read an article about finding a country based on the IP address. In fact, I used one for my work, but I don't know how to do it.
Next, I will share the translation http://www.codeproject.com/kb/aspnet/aspxcode_net.aspxwith everyone;
Principle: The IP addresses in various countries now have an IP address begin number and an IP end number. The data starting from the country and ending data are stored in the database.
Finally, a calculation formula is used to convert a real IP address to an IP number, which is located between begin and end in the database. If so, it is in this country;
The IP number of each country should be the subject of the country. It should not be changed.ArticleTo download;
IP number calculation formula:
IP number = 16777216 * W + 65536 * X + 256 * Y + Z ( 1 )
Where
IP address = W. x. y. Z
Note: 16777216,65536, 256; this number is a coefficient, just like the circumference rate of 3.14
W. x. y. Z corresponds to the actual IP address, for example: 192.168.0.19; Link
Eg:
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
In this way, an IP number is obtained. Now we can go to our database to find the correct IP address segment, that is, the country where the IP address is located.
About slave DatabaseCodeI won't talk much about it.
The key is to understand the principle and find the solution;
National Standard IP Range download: http://files.cnblogs.com/caodaiming/ip-to-country.zip