What is this?
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 |
|---|---|---|---|---|---|---|
| ❌ | ✔️ | ✔️ | ✔️ | ✔️ | ||
| cloudflare | ✔️ | ❌ | ✔️ | ✔️ | ✔️ | |
| openDNS | ❌ | ❌ | ✔️ | ✔️ | ✔️ | |
| akamai | ✔️ | ❌ | ✔️ | ✔️ | ✔️ | |
| ipify | ✔️ | ❌ | ❌ | ✔️ | ✔️ | |
| icanhazip | ✔️ | ❌ | ❌ | ✔️ | ✔️ | |
| matrix | ❌ | ✔️ | ❌ | ✔️ | ✔️ | |
| framasoft | ❌ | ✔️ | ❌ | ✔️ | ✔️ | |
| ifconfig.me | ✔️ | ❌ | ❌ | ✔️ | ✔️ |
Installation
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.HTTPSpublicaddr.DNSpublicaddr.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.IPv4publicaddr.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.CLOUDFLAREpublicaddr.GOOGLEpublicaddr.OPENDNSpublicaddr.AKAMAIpublicaddr.IPIFYpublicaddr.ICANHAZIPpublicaddr.MATRIXpublicaddr.FRAMASOFTpublicaddr.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/
Metadata
Release files for publicaddr 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| publicaddr-1.0.0.tar.gz | 10.8 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| publicaddr-1.0.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 27.3 kB
Release files / publicaddr-1.0.0.tar.gz
| Download URL | publicaddr-1.0.0.tar.gz |
|---|---|
| Size | 10.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
49ca254d952aaf66ab042f601a5ae525a5c0597f07f18fab664d88e8d86113b5
|
|
BLAKE2b-256 checksum How to use checksums |
80e5c9e74198a8a840e2db1aeba6435a88b559c3a727b90fc37f16810bb8c76b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 12, 2026.
Transparency logRelease files / publicaddr-1.0.0-py3-none-any.whl
| Download URL | publicaddr-1.0.0-py3-none-any.whl |
|---|---|
| Size | 16.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
7558a07247419b5f0449e7247dda238d80a931ea5c6a1e203c1550fb2fda52c8
|
|
BLAKE2b-256 checksum How to use checksums |
116db5e29e181be310de68796dfd396dda6f5d2f798640cff4924713b4502a24
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 12, 2026.
Transparency log