ubuntu 系統時用 –
sudo apt-get install geoip-bin geoip-database
參考: http://kbeezie.com/geoiplookup-command-line/
以下結果是顯示數量
cat ./ip_test.txt | sort | uniq | xargs -n 1 geoiplookup { } | sort | uniq -c | sort
tcpdump -ntr /var/log/pflog | awk '{print }' | sed -r 's/ \>.*//g' | \
grep -oE '[0-9]{1,}.[0-9]{1,}.[0-9]{1,}.[0-9]{1,}' | grep -v "0.0.0.0" | \
sort -n | uniq | xargs -n 1 geoiplookup { } | sort | uniq -c | sort -n | sed -r 's/ GeoIP Country Edition://g'
python 程式使用
參考: https://pythonhosted.org/python-geoip/
Installation
You can get the library directly from PyPI:
pip install python-geoip
If you also want the free MaxMind Geolite2 database you can in addition:
pip install python-geoip-geolite2