Discovers your public IP address using pre-defined checkers (external services).
- Python 2.7, 3.4, 3.5, PyPy
Install with latest stable version from PyPI:
pip install pifor install the latest stable version from source:
pip install https://bitbucket.org/barseghyanartur/pif/get/stable.tar.gzor install into python path:
python setup.py installThat's all. See the Usage and examples section for more.
Get public IP:
from pif import get_public_ip
get_public_ip()Get public IP using preferred checker:
get_public_ip('v4.ident.me')List available checkers:
from pif.utils import list_checkers
list_checkers()pif ships with a number of pre-defined public IP checkers. But you may extend it by defining your own ones as follows.
from pif.base import BaseIPChecker, registry
class MyPublicIPChecker(BaseIPChecker):
uid = 'mypublicipchecker' # UID of the checker
def get_public_ip(self):
# TODO: Implement your logic
# Register the checker
registry.register(MyPublicIPChecker)
# Get public IP using the preferred checker
get_public_ip('mypublicipchecker')It's possible to get your public IP address from command line using the pif.commands.get_public_ip module.
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 1Simply type:
./runtests.pyor use tox:
toxor use tox to check specific env:
tox -e py35GPL 2.0/LGPL 2.1
For any issues contact me at the e-mail given in the Author section.
Artur Barseghyan <artur.barseghyan@gmail.com>