I am curious about what is the principle of acquiring Geolocation tools based on IP? What does each digit in the IP represent? Can I complete this task without using a third-party interface locally?
Reply content:
I am curious about what is the principle of acquiring Geolocation tools based on IP? What does each digit in the IP represent? Can I complete this task without using a third-party interface locally?
What is an ISP? Simple understanding is like China Telecom, Unicom, mobile and other network providers.
With the supplier will be able to surf the Internet, you will be able to get a temporary IP through the modem (periodic change).
But is this IP really given at random? How is it random?
APNIC (Asia-Pacific Internet Information Center), this is the organization. is now one of the five regional Internet registries operating in the world, assigning an international organization of Class B IP addresses. It provides global support for Internet operational allocation and registration services. These members include a non-profit, membership-based organization of network service providers, national Internet registries, and similar organizations. APNIC is responsible for the Asia Pacific region, comprising 56 economic zones.
Assume that Apnic has assigned 1 million IP addresses to China. Then to the domestic, through the domestic top management organizations (do not know who) and then assigned to the telecommunications, mobile, unicom, mobile and other top ISPs. Then these ISPs, and then according to their own rules to the different provinces of the country redistribution, and then to the city, county, township and so on.
IP地址每个数字并不代表什么,国内顶级ISP的IP分配是公开的,因此只有拿到这个库,才能根据用户的IP来知道用户是什么位置的由于这个库的更新并不及时,所以并不100%准确
Update
The domestic more popular IP library is pure. Official website: http://www.cz88.net/can be downloaded in the upper right corner. After installation, a file in the directory .dat
is the IP allocation database. Combined with the use of PHP and other language use Baidu a search there.
PHP installation GeoIP extensions and databases get information about the country/city/latitude and longitude of your visitors based on IP
Http://php.net/manual/zh/ref ....
sudo apt-get install libgeoip-dev
pecl install geoip-1.1.0
Note: The beta version specifies the version number. If it is apt-installed PHP, install PHP5-GEOIP this package directly.
PHP.ini Add:
extension=geoip.sogeoip.custom_directory="/usr/share/GeoIP"
Free download Geolitecity database (18MB after decompression):
http://dev.maxmind.com/geoip/...
Wget http://geolite.maxmind.com/do ...
Gunzip GeoLiteCity.dat.gz
sudo mkdir-v/usr/share/geoip
sudo mv-v geolitecity.dat/usr/share/geoip/geoipcity.dat
Test:
Php-a
AS [country_code] => CN [country_code3] => CHN [country_name] => China //国家 [region] => 22 [city] => Beijing //城市 [postal_code] => [latitude] => 39.928901672363 //纬度 [longitude] => 116.38829803467 //经度 [dma_code] => 0 [area_code] => 0)
PHP easy to implement "nearby people" function, according to IP to determine latitude and longitude, based on latitude and longitude to calculate distance
No third-party interfaces are used, and matching queries are required using IP libraries provided by third parties.
But none of them is 100% accurate.
Recommend a service provider that provides both an interface and an IP library: http://www.ipip.net/
They all have their own IP libraries. Unless you have an IP library locally.
Third-party interfaces can ip
obtain geo-location information, in fact, their local saved ip => address -info
database mapping, because their database has a large number of storage ip
and geographical relationship, so we can provide third-party services
Of course, you can do it yourself, but you probably don't have that huge database support.
If you still do not want to request a third-party interface, you can download a
Free GeoIP Database
This is a database problem, here is an open source code, to study it yourself. Http://git.oschina.net/lionsoul/ip2region
Nginx+geo+fastcgi_params
Welcome Phper Join Hnphper Group 233415606
pecl install qqwry-beta
Qqwry you deserve to have.
IP is not in fact a random division. If you have a heart, you will find. The IP segment is tightly coupled with the region in which it resides. Your next-door city and the IP of your city may be contiguous.