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.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| publicaddr-1.0.1.tar.gz | 10.8 kB | With provenance | Details for publicaddr-1.0.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| publicaddr-1.0.1-py3-none-any.whl | Python 3 | none | any | Details for publicaddr-1.0.1-py3-none-any.whl |
Total release size: 27.4 kB
Release files / publicaddr-1.0.1.tar.gz
| Download URL | publicaddr-1.0.1.tar.gz |
|---|---|
| Size | 10.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
08368bf5073e169dca1147be8cb7fc14361fb7367e5bbd4a8da6eb93cef500c0
|
|
BLAKE2b-256 checksum How to use checksums |
24660fa6ac016353369a83785552f6fcfdb3770a28c1949b70b8c71ec3825e0f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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 Nov 4, 2026.
Transparency logRelease files / publicaddr-1.0.1-py3-none-any.whl
| Download URL | publicaddr-1.0.1-py3-none-any.whl |
|---|---|
| Size | 16.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
1bd1bcc17a43ee872c7e729188ea92f25df560bf336086fefaaed53334f8688f
|
|
BLAKE2b-256 checksum How to use checksums |
f5070b62b60e7d6f3cb519db62c1ea953ed844bd038d9e00a51fcb89cc57bb40
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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 Nov 4, 2026.
Transparency logSecurity for publicaddr 1.0.1
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.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for publicaddr-1.0.1.tar.gz
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 Nov 4, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.