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 with IPv4 and IPv6:
- Google (DNS & HTTP & STUN)
- Cloudflare (DNS & HTTP)
- OpenDNS (DNS)
- Akamai (DNS & HTTP)
- Ipify (HTTP)
- Icanhazip (HTTP)
- Matrix (STUN)
- Framasoft (STUN)
- Ifconfig.me (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 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.MULLVAD
(disabled by default in config because IPv6 is not supported)publicaddr.IFCONFIG_ME
Custom configuration
See the default configuration file
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
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
Hashes for publicaddr-0.14.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 91cbf183d2d6c7c761f791da9733c75921eaf99e4bce6a62087ae2667be3afca |
|
MD5 | fa5acc340fcdb09b1fad4fdedf31afdd |
|
BLAKE2b-256 | ad66da2ec2e5d5f170b6a2a921aca606af13f4a9dabab7317cc633b46affea81 |