Skip to main content

Getting your public IP v4 and v6

Project description

What is this?

Testing Build Publish

License: MIT PyPI - Python Version

Simple python module for getting your public IP V4 and V6 from several providers in random mode.

Supported providers:

  • Google (DNS & HTTP & STUN)
  • Cloudflare (DNS)
  • OpenDNS (DNS)
  • Akamai (DNS & HTTP)
  • Ipify (HTTP)
  • Icanhazip (HTTP)
  • Matrix (STUN)
  • Framasoft (STUN)

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=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'}

Get IPv4 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'}

Get IPv6 only

Get your public IPv6 with default provider (Google with DNS protocol).

import publicaddr

publicaddr.get(ip=publicaddr.IPv6)
{'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.

import publicaddr

myip = publicaddr.get(provider=publicaddr.CLOUDFLARE, ip=publicaddr.IPv6, 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

Default constants for IP version:

  • publicaddr.IPv4
  • publicaddr.IPv6

Default constants for transport protocol:

  • publicaddr.HTTPS
  • publicaddr.DNS
  • publicaddr.STUN

Custom configuration

See the default configuration file

For developpers

Run test units

python3 -m unittest discover tests/

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

publicaddr-0.8.0.tar.gz (6.9 kB view hashes)

Uploaded Source

Built Distribution

publicaddr-0.8.0-py3-none-any.whl (9.5 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page