
IP Geography
Recently, I had to deal with a program for tracking click statistics of a certain ad exchange system. When clicking, as usual, information about the click was collected (on which page happened, what time, browser, ad ID and IP). The task of statistics was to find out the city from which the transition took place. Previously, I was not particularly interested in this, therefore, only now I have started a deeper acquaintance with GeoIP systems.
Besides, how did it succeed
? At first I remembered all kinds of geoip tables there, which can now be foundwithout much difficulty more difficult than before. But the abbreviated options are on the sites-collectors of the databases. Below one of them is the
abbreviated base
maxmind.com - the site itself. there you can check the geoip database.
The option in my case has disappeared - I would have to have the whole list, but it’s not small and make selections from tables. and after some time it will be necessary to update the table. in general laziness made me look for other ways. while searching, I found an interesting service http://geoiptool.com/ which performs the standard operation of any geoip service, but also imposes it on a google map .

Very funny. Habr - here
As a result, I found http://www.ip2city.ru/ - an open base of IP addresses. I stopped on it. What distinguished it from other services was the ability to provide data of the form
field1 = value1
field2 = value2
...
which is caused by a simple get requestwww.ip2city.ru/ip2city.php?ip=ххх.ххх.ххх.ххх
and such data is quite easily received from third-party servers and parsed
$ IP = "00.00.00.00"; // or IP from anywhere (in my case from the database)
$ lines = file ('http://www.ip2city.ru/ip2city.php?ip='.$IP);
$ city = trim (str_replace ('=', '', strstr ($ lines ['0'], '=')));
$ country = trim (str_replace ('=', '', strstr ($ lines ['4'], '=')));
Naturally, with such work, PHP will draw the page for a long time until it receives all the data from the server (parsing itself is fast), so I would recommend the IP -> city operation after the page loads.
This is my first topic, I apologize in advance for the mistakes. I hope someone comes in handy
Besides, how did it succeed
? At first I remembered all kinds of geoip tables there, which can now be found
abbreviated base
maxmind.com - the site itself. there you can check the geoip database.
The option in my case has disappeared - I would have to have the whole list, but it’s not small and make selections from tables. and after some time it will be necessary to update the table. in general laziness made me look for other ways. while searching, I found an interesting service http://geoiptool.com/ which performs the standard operation of any geoip service, but also imposes it on a google map .
Very funny. Habr - here
As a result, I found http://www.ip2city.ru/ - an open base of IP addresses. I stopped on it. What distinguished it from other services was the ability to provide data of the form
field1 = value1
field2 = value2
...
which is caused by a simple get requestwww.ip2city.ru/ip2city.php?ip=ххх.ххх.ххх.ххх
and such data is quite easily received from third-party servers and parsed
$ IP = "00.00.00.00"; // or IP from anywhere (in my case from the database)
$ lines = file ('http://www.ip2city.ru/ip2city.php?ip='.$IP);
$ city = trim (str_replace ('=', '', strstr ($ lines ['0'], '=')));
$ country = trim (str_replace ('=', '', strstr ($ lines ['4'], '=')));
Naturally, with such work, PHP will draw the page for a long time until it receives all the data from the server (parsing itself is fast), so I would recommend the IP -> city operation after the page loads.
This is my first topic, I apologize in advance for the mistakes. I hope someone comes in handy