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.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/
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
File details
Details for the file publicaddr-0.16.0.tar.gz
.
File metadata
- Download URL: publicaddr-0.16.0.tar.gz
- Upload date:
- Size: 10.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 35eb8d1c4e90f53aea3130d28a33cd2ae16c263bfb645f0ba3d49bde2315950b |
|
MD5 | 48e38d04d2c818c100d9948a17a7c2ff |
|
BLAKE2b-256 | 669b641ae20f9427a5616a4ffe07f942b784138d345ddc97984750fa5c01cde5 |
Provenance
The following attestation bundles were made for publicaddr-0.16.0.tar.gz
:
Publisher:
publish.yml
on dmachard/python-publicaddr
-
Statement type:
https://in-toto.io/Statement/v1
- Predicate type:
https://docs.pypi.org/attestations/publish/v1
- Subject name:
publicaddr-0.16.0.tar.gz
- Subject digest:
35eb8d1c4e90f53aea3130d28a33cd2ae16c263bfb645f0ba3d49bde2315950b
- Sigstore transparency entry: 148207785
- Sigstore integration time:
- Predicate type:
File details
Details for the file publicaddr-0.16.0-py3-none-any.whl
.
File metadata
- Download URL: publicaddr-0.16.0-py3-none-any.whl
- Upload date:
- Size: 16.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7a6bb546137139508974196301a99c12e1c57b2324587b06cde36548066fff6a |
|
MD5 | 0f8454ab54d3319d179b8145a800f293 |
|
BLAKE2b-256 | 2216ee56f4ef56eebe3305598661aa7fbba77407f35bd3bd6c6bb574dfbef561 |
Provenance
The following attestation bundles were made for publicaddr-0.16.0-py3-none-any.whl
:
Publisher:
publish.yml
on dmachard/python-publicaddr
-
Statement type:
https://in-toto.io/Statement/v1
- Predicate type:
https://docs.pypi.org/attestations/publish/v1
- Subject name:
publicaddr-0.16.0-py3-none-any.whl
- Subject digest:
7a6bb546137139508974196301a99c12e1c57b2324587b06cde36548066fff6a
- Sigstore transparency entry: 148207786
- Sigstore integration time:
- Predicate type: