公用IP地址检查器。
pif的Python项目详细描述
使用预定义的检查程序(外部服务)发现您的公共IP地址。
先决条件
- python 2.7、3.4、3.5、pypy
安装
使用来自pypi的最新稳定版本安装:
pip install pif
或者从源安装最新的稳定版本:
pip install https://bitbucket.org/barseghyanartur/pif/get/stable.tar.gz
或安装到python路径:
python setup.py install
就这些。有关详细信息,请参见Usage and examples部分。
用法和示例
基本用法
获取公共IP:
frompifimportget_public_ipget_public_ip()
使用首选检查程序获取公共IP:
get_public_ip('v4.ident.me')
列出可用的方格:
frompif.utilsimportlist_checkerslist_checkers()
注册自定义IP检查器
pif带有许多预定义的公共ip检查程序。但你可以延长 它通过定义你自己的如下。
frompif.baseimportBaseIPChecker,registryclassMyPublicIPChecker(BaseIPChecker):uid='mypublicipchecker'# UID of the checkerdefget_public_ip(self):# TODO: Implement your logic# Register the checkerregistry.register(MyPublicIPChecker)# Get public IP using the preferred checkerget_public_ip('mypublicipchecker')
命令行用法
可以使用 pif.commands.get_public_ip模块。
optional arguments: -h, --help show this help message and exit -c PREFERRED_CHECKER, --checker PREFERRED_CHECKER `preferred_checker` value -v VERBOSE, --verbose VERBOSE `verbose` value
Example: | (simple) |
---|
get-public-ip
Example: | (with preferred checked and verbose output) |
---|
get-public-ip -c v4.ident.me -v 1
测试
只需键入:
./runtests.py
或使用毒物:
tox
或使用毒性检查特定环境:
tox -e py35
许可证
gpl 2.0/lgpl 2.1
支架
如有任何问题,请通过作者部分中提供的电子邮件与我联系。