Skip to main content

Discovers your public IP address using pre-defined checkers (external services).

Prerequisites

  • Python 2.7, 3.4, 3.5, PyPy

Installation

Install with latest stable version from PyPI:

pip install pif

or install the latest stable version from source:

pip install https://bitbucket.org/barseghyanartur/pif/get/stable.tar.gz

or install into python path:

python setup.py install

That’s all. See the Usage and examples section for more.

Usage and examples

Basic usage

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()

Registering a custom IP checker

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')

Command line usage

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 1

Testing

Simply type:

./runtests.py

or use tox:

tox

or use tox to check specific env:

tox -e py35

License

GPL 2.0/LGPL 2.1

Support

For any issues contact me at the e-mail given in the Author section.

Author

Artur Barseghyan <artur.barseghyan@gmail.com>

Release files for pif 0.8.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pif 0.8.2
File Size Uploaded
pif-0.8.2.tar.gz 21.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pif 0.8.2
File Interpreter ABI Platform
pif-0.8.2-py2.py3-none-any.whl Python 3, Python 2 none any Details

Total release size: 40.9 kB

Release files / pif-0.8.2.tar.gz

Download URL pif-0.8.2.tar.gz
Size 21.1 kB
Tags Source
SHA-256 checksum
How to use checksums
5ee4a13a52a6facefb510c4740a28bc33f16ae7fe3b2cc523080102dfddf5bbb
BLAKE2b-256 checksum
How to use checksums
be9277fec5e8eded1e3c53d43e36a0a8c5463cdaa4af991c65e4dc6cc14a2fb4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / pif-0.8.2-py2.py3-none-any.whl

Download URL pif-0.8.2-py2.py3-none-any.whl
Size 19.8 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
dbd3a5032ed8417780d3632e226ea67438751939adbb95e90f471a4565fe95fb
BLAKE2b-256 checksum
How to use checksums
204211a03f86acb097f2a1ec329524eecae806cc76ed9fe496bd127e198d895a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

0.8.2 This release

2 release files

0.8.1

2 release files

0.8

2 release files

0.7.4

2 release files

0.7.3

2 release files

0.7.2

2 release files

0.7.1

1 release file

0.7

1 release file

0.6

1 release file

0.5

1 release file

0.4

1 release file

0.3

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page