Getting your public IP v4 and v6
Project description
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/
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file publicaddr-0.19.0.tar.gz.
File metadata
- Download URL: publicaddr-0.19.0.tar.gz
- Upload date:
- Size: 10.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0baf46a72ef5bcaf30baa3b2395220b38356f970e348883277b67d8d60594f00
|
|
| MD5 |
12c6e4676385c9961c0dd74dba8fa3c9
|
|
| BLAKE2b-256 |
2f1207813d7c916118c096f3e42beb56a7206086f2556896f9a8ef72ff33f19d
|
Provenance
The following attestation bundles were made for publicaddr-0.19.0.tar.gz:
Publisher:
publish.yml on dmachard/python-publicaddr
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
publicaddr-0.19.0.tar.gz -
Subject digest:
0baf46a72ef5bcaf30baa3b2395220b38356f970e348883277b67d8d60594f00 - Sigstore transparency entry: 954617527
- Sigstore integration time:
-
Permalink:
dmachard/python-publicaddr@4ed5dbf75a62df89d37dbbb3862f033002ccb8b8 -
Branch / Tag:
refs/tags/v0.19.0 - Owner: https://github.com/dmachard
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@4ed5dbf75a62df89d37dbbb3862f033002ccb8b8 -
Trigger Event:
release
-
Statement type:
File details
Details for the file publicaddr-0.19.0-py3-none-any.whl.
File metadata
- Download URL: publicaddr-0.19.0-py3-none-any.whl
- Upload date:
- Size: 16.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6bfd2fa76936e7feae76488c3ba24f256799627b2bcbe59496c4e70e77d95c6b
|
|
| MD5 |
0700da81d409b72f8b57baac28bf18a3
|
|
| BLAKE2b-256 |
0aa1c9ab4fdc85d28632fedc81e611d01cb1daf7fcbc1a10cb8488b72367d00b
|
Provenance
The following attestation bundles were made for publicaddr-0.19.0-py3-none-any.whl:
Publisher:
publish.yml on dmachard/python-publicaddr
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
publicaddr-0.19.0-py3-none-any.whl -
Subject digest:
6bfd2fa76936e7feae76488c3ba24f256799627b2bcbe59496c4e70e77d95c6b - Sigstore transparency entry: 954617555
- Sigstore integration time:
-
Permalink:
dmachard/python-publicaddr@4ed5dbf75a62df89d37dbbb3862f033002ccb8b8 -
Branch / Tag:
refs/tags/v0.19.0 - Owner: https://github.com/dmachard
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@4ed5dbf75a62df89d37dbbb3862f033002ccb8b8 -
Trigger Event:
release
-
Statement type: