按IP地址查找国家代码(ISO 3166)。
ip2countr的Python项目详细描述
关于
按IP地址查找国家代码(ISO 3166)。
安装
$ pip install ip2country
或
$ python setup.py install
如何使用
首先:实现istore接口
必须在ip2ccountry/interfaces.py中实现IStore接口。
example/store中有一个示例实现。 此实现将所有记录存储在系统内存中。
第二:存储记录
store=Store()parser=Parser(store)withopen(RECORD_FILE)asfp:parser.do(fp)
有关详细信息,请参见examples/lookup.py:load。
第三:查找ipaddress
store=Store()record=store.lookup(IP_ADDRESS)ifrecordisNone:print('Record not found')else:print('{0} is allocated to {1}'.format(IP_ADDRESS,record.cc))
有关详细信息,请参见examples/lookup.py:main。
运行测试
$ tox
许可证
IP2国家是根据麻省理工学院的许可证授权的。请参见./license.rst。