Skip to main content

Testing Build Publish

What is this?

License: MIT

Simple python module for getting your public IP V4 and V6 from several providers in random mode with also several protocols (DNS, HTTPS and STUN).

Supported providers

IP Checker HTTPS STUN DNS IPv4 IPv6 Use Policy
google ✔️ ✔️ ✔️ ✔️
cloudflare ✔️ ✔️ ✔️ ✔️
openDNS ✔️ ✔️ ✔️
akamai ✔️ ✔️ ✔️ ✔️
ipify ✔️ ✔️ ✔️
icanhazip ✔️ ✔️ ✔️
matrix ✔️ ✔️ ✔️
framasoft ✔️ ✔️ ✔️
ifconfig.me ✔️ ✔️ ✔️

Installation

python 3.13.x python 3.12.x python 3.11.x python 3.10.x

This module can be installed from pypi website

pip install publicaddr

Lookup for IPv4 and IPv6

Lookup for your public IPs from random providers with DNS or HTTP protocols with 3 retries if no ips are returned. This is the default behaviour of the lookup function.

import publicaddr

publicaddr.lookup()
{'ip4': 'x.x.x.x', 'ip6': 'x:x:x:x:x:x:x:x', 'provider': 'opendns',
'proto': 'dns', 'duration': '0.037'}

Configuration

This module can be configurated with environment variables

Variables Description
PUBLICADDR_DEBUG debug mode 1 or 0
PUBLICADDR_TIMEOUT timeout, default is 2s
PUBLICADDR_RETRIES retries, default is 3
PUBLICADDR_IPV6_ENABLED enable ipv6 with 1 or 0 to disable
PUBLICADDR_LOOKUP_HTTPS lookup with HTTPS protocol (1 or 0 to disable)
PUBLICADDR_LOOKUP_DNS lookup with DNS protocol (1 or 0 to disable)
PUBLICADDR_LOOKUP_STUN lookup with STUN protocol (1 or 0 to disable)

Specific lookups

Lookup for public IP with specific protocol

Lookup for your public IPs from random DNS providers with specific protocol.

import publicaddr

publicaddr.lookup(providers=publicaddr.DNS, retries=2)
{'ip4': 'x.x.x.x', 'ip6': 'x:x:x:x:x:x:x:x', 'provider': 'opendns',
'proto': 'dns', 'duration': '0.037'}

Default constants for transport protocol:

  • publicaddr.HTTPS
  • publicaddr.DNS
  • publicaddr.STUN

Get IPv4 or IPv6 only

Get your public IPv4 with default provider (Google with DNS protocol).

import publicaddr

publicaddr.get(ip=publicaddr.IPv4)
{'ip': 'x.x.x.x', 'duration': '0.025'}

Default constants for IP version:

  • publicaddr.IPv4
  • publicaddr.IPv6

Get IP with specific provider

Example to use the provider Cloudflare instead of the default one.

import publicaddr

myip = publicaddr.get(provider=publicaddr.CLOUDFLARE, proto=publicaddr.DNS)
{'ip': 'x:x:x:x:x:x:x:x', 'duration': '0.020'}

Default constants for providers:

  • publicaddr.CLOUDFLARE
  • publicaddr.GOOGLE
  • publicaddr.OPENDNS
  • publicaddr.AKAMAI
  • publicaddr.IPIFY
  • publicaddr.ICANHAZIP
  • publicaddr.MATRIX
  • publicaddr.FRAMASOFT
  • publicaddr.IFCONFIG_ME

For developpers

Run from source

sudo apt install python3-venv
python3 -m venv venv
source venv/bin/activate
python3 -m pip install -r requirements.txt
python3 example.py

Custom configuration

See the default configuration file

Run test units

python3 -m unittest discover tests/

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

publicaddr-0.19.2.tar.gz (10.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

publicaddr-0.19.2-py3-none-any.whl (16.6 kB view details)

Uploaded Python 3

File details

Details for the file publicaddr-0.19.2.tar.gz.

File metadata

  • Download URL: publicaddr-0.19.2.tar.gz
  • Upload date:
  • Size: 10.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for publicaddr-0.19.2.tar.gz
Algorithm Hash digest
SHA256 bbcbad881ae5045c86ddf1a177e8ddebfb18d3f7b92a4ab1eed61fd598ad4929
MD5 d25353fb41cd7b82ac43a454fa6cc74b
BLAKE2b-256 d3fecbcba9cf4a1370691d77fb0e7126e6e2122649c1314ea1387ab8a6c118fe

See more details on using hashes here.

Provenance

The following attestation bundles were made for publicaddr-0.19.2.tar.gz:

Publisher: publish.yml on dmachard/python-publicaddr

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file publicaddr-0.19.2-py3-none-any.whl.

File metadata

  • Download URL: publicaddr-0.19.2-py3-none-any.whl
  • Upload date:
  • Size: 16.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for publicaddr-0.19.2-py3-none-any.whl
Algorithm Hash digest
SHA256 fd3c3024302de4cf0cf48898e4d5c0a004735a8c757bc8993edd91399c244b28
MD5 0ec588a6a8b92f609429cfd1b3fded1b
BLAKE2b-256 2584c5ca96ee7f570032c403e0ab80ed64b7f60e8ff09a4f19210c75953a1dd9

See more details on using hashes here.

Provenance

The following attestation bundles were made for publicaddr-0.19.2-py3-none-any.whl:

Publisher: publish.yml on dmachard/python-publicaddr

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

1.0.0

2 files

This release

0.19.2 This release

2 files

0.19.1

2 files

0.19.0

2 files

0.18.0

2 files

0.17.0

2 files

0.16.0

2 files

0.15.0

2 files

0.14.2

2 files

0.14.1

2 files

0.14.0

2 files

0.13.0

2 files

0.12.1

2 files

0.12.0

2 files

0.11.1

2 files

0.11.0

2 files

0.10.1

2 files

0.10.0

2 files

0.9.0

2 files

0.8.0

2 files

0.7.0

2 files

0.6.1

2 files

0.6.0

2 files

0.5.0

2 files

0.4.0

2 files

0.3.0

2 files

0.2.0

2 files

0.1.0

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page