c、执行更新
查看geoipupdate帮助文件,了解有哪些参数可以使用! -d 参数将文件下载到指定目录,-v 参数就是显示下载过程明细信息。
$ /usr/local/bin/geoipupdate -h Usage: geoipupdate [-Vhv] [-f license_file] [-d custom directory] -d DIR store downloaded files in DIR -f FILE use configuration found in FILE (see GeoIP.conf(5) man page) -h display this help text -v use verbose output -V display the version and exit
执行更新命令,看网络情况,本文将文件下载到 /mnt/data/geolite2/目录 。
$ ll /mnt/data/geolite2/ && cd $_ 总用量 0 $ sudo /usr/local/bin/geoipupdate -d /mnt/data/geolite2/ -v $ ll 总用量 34088 -rw-r--r--. 1 root root 32553611 12月 19 18:14 GeoLite2-City.mmdb -rw-r--r--. 1 root root 2349406 12月 19 18:14 GeoLite2-Country.mmdb
如何配置计划任务定时更新 GeoLite2 请自行解决。mmdb
三、安装 GeoLite2API 调用程序
官方提供 .NET (C#)、C、Java、Perl、Python、Apache API调用。其他第三方接口也有,但官方不提供技术支持, 详情点击这里。
本文使用 C 语言API接口进行调用测试,其他语言请参考官方指导自行解决! C语言API GitHub 下载地址
$ sudo wget https://github.com/maxmind/libmaxminddb/releases/download/1.0.3/libmaxminddb-1.0.3.tar.gz $ sudo tar xzvf libmaxminddb-1.0.3.tar.gz $ cd libmaxminddb-1.0.3 $ sudo ./configure $ sudo make $ sudo make install
查看帮助文档
$ /usr/local/bin/mmdblookup --help
mmdblookup --file /path/to/file.mmdb --ip 1.2.3.4 [path to lookup]
This application accepts the following options:
--file (-f) The path to the MMDB file. Required.
--ip (-i) The IP address to look up. Required.
--verbose (-v) Turns on verbose output. Specifically, this causes this
application to output the database metadata.
--version Print the program's version number and exit.
--help (-h -?) Show usage information.
If an IP's data entry resolves to a map or array, you can provide
a lookup path to only show part of that data.
For example, given a JSON structure like this:
{
"names": {
"en": "Germany",
"de": "Deutschland"
},
"cities": [ "Berlin", "Frankfurt" ]
}
You could look up just the English name by calling mmdblookup with a lookup path of:
mmdblookup --file ... --ip ... names en
Or you could look up the second city in the list with:
mmdblookup --file ... --ip ... cities 1
Array numbering begins with zero (0).
If you do not provide a path to lookup, all of the information for a given IP
will be shown.四、测试
本文来自电脑杂谈,转载请注明本文网址:
http://www.pc-fly.com/a/jisuanjixue/article-27536-2.html
015-10W*1
易烊千玺最棒