FreeBSD 7.0-RELEASE-i386 + PHP5 + Apache2.2
# cd /usr/ports/net/pecl-geoip && make install clean # apachectl restart # cd ~ # fetch http://www.maxmind.com/download/geoip/database/GeoIP.dat.gz # gunzip GeoIP.dat.gz # mv GeoIP.dat /usr/local/share/GeoIP/GeoIP.dat # fetch http://www.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz # gunzip GeoLiteCity.dat.gz # mv GeoLiteCity.dat /usr/local/share/GeoIP/GeoIPCity.dat <?php echo geoip_database_info(GEOIP_COUNTRY_EDITION); $country = geoip_record_by_name('wangblog.org'); if($country){ echo "\nThis host is located in: \n"; print_r($country); } ?>
可以写个定时更新IP地址库的程序:
cd ~ /usr/bin/fetch http://www.maxmind.com/download/geoip/database/GeoIP.dat.gz /usr/bin/gunzip GeoIP.dat.gz mv GeoIP.dat /usr/local/share/GeoIP/GeoIP.dat /usr/bin/fetch http://www.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz /usr/bin/gunzip GeoLiteCity.dat.gz mv GeoLiteCity.dat /usr/local/share/GeoIP/GeoIPCity.dat 以上保存为:update-ipdata-cron.sh crontab -e 添加以下一行,每月5日0点10分运行: 10 0 5 * * /bin/csh /path/to/update-ipdata-cron.sh
0 Comments