python3-GeoIP で国を判定する

デフォルトでインストールされている「python3-GeoIP」で国を判定します。


インストール

$ sudo dnf install python3-GeoIP

サンプル

$ python
Python 3.10.5 (main, Jun 9 2022, 00:00:00) [GCC 12.1.1 20220507 (Red Hat 12.1.1-1)] on linux
Type “help”, “copyright”, “credits” or “license” for more information.
>> import GeoIP
>> gi = GeoIP.new(GeoIP.GEOIP_MEMORY_CACHE)
>>
>> gi.country_code_by_name(“www.google.co.jp”)
‘US’
>> gi.country_name_by_name(“youtube.com”)
‘United States’
>> gi.country_code_by_addr(“24.24.24.24”)
‘US’
>> gi.country_name_by_addr(“24.24.24.24”)
‘United States’
>> gi.range_by_ip(“68.180.206.184”)
(‘68.179.128.0’, ‘68.181.255.255’)

1つのコメント

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です