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.
Supported providers:
- Google (DNS & HTTP)
- Cloudflare (DNS)
- OpenDNS (DNS)
- Akamai (DNS & HTTP)
- Ipify (HTTP)
- Icanhazip (HTTP)
Installation
This module can be installed from pypi website
pip install publicaddr
Lookup for IPv4 and v6
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'}
Lookup for IPv4 and v6 with DNS protocol only
Lookup for your public IPs from random DNS providers only.
import publicaddr
publicaddr.lookup(providers=DNS_PROVIDERS, retries=2)
{'ip4': 'x.x.x.x', 'ip6': 'x:x:x:x:x:x:x:x', 'provider': 'OpenDNS',
'proto': 'DNS', 'duration': '0.037'}
Get IPv4 only
Get your public IPv4 with default provider (Google with DNS protocol).
import publicaddr
publicaddr.get(ipversion=4)
{'ip': 'x.x.x.x', 'duration': '0.025'}
Get IPv6 only
Get your public IPv6 with default provider (Google with DNS protocol).
import publicaddr
publicaddr.get(ipversion=6)
{'ip': 'x:x:x:x:x:x:x:x', 'duration': '0.063'}
Get IP with specific provider
Example to use the provider Cloudflare instead of the default one.
from publicaddr import get, PROVIDER_CLOUDFLARE, IP_V6, PROTO_DNS
myip = get(provider=PROVIDER_CLOUDFLARE, ipversion=IP_V6, ipproto=PROTO_DNS)
{'ip': 'x:x:x:x:x:x:x:x', 'duration': '0.020'}
For developpers
Run test units
python3 -m unittest -v 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
Hashes for publicaddr-0.6.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | aeae006f0590a667315e591457d18b10bd6297a41c28554d9796789757cb6475 |
|
MD5 | 24daef97925cfdd54f62ba134d5a07eb |
|
BLAKE2b-256 | 7b3366e62d1ffcba7f7dd1285041c0da135b00d44ac1c654be05c23e25a4bebd |