Metadata-Version: 2.1
Name: publicaddr
Version: 0.4.0
Summary: Getting your public IP v4 and v6
Home-page: https://github.com/dmachard/python-publicaddr
Author: Denis MACHARD
Author-email: d.machard@gmail.com
Keywords: public ip dns http google akamai opendns cloudflare
Platform: any
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Operating System :: OS Independent
Classifier: Topic :: Software Development :: Libraries
Description-Content-Type: text/markdown
License-File: LICENSE

# Intro

![Testing](https://github.com/dmachard/python-publicaddr/workflows/Testing/badge.svg) ![Build](https://github.com/dmachard/python-publicaddr/workflows/Build/badge.svg) ![Publish](https://github.com/dmachard/python-publicaddr/workflows/Publish/badge.svg) 

[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
![PyPI - Python Version](https://img.shields.io/pypi/pyversions/publicaddr)

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

Supported providers:
- Google (DNS)
- Cloudflare (DNS)
- OpenDNS (DNS)
- Akamai (HTTP)

## Installation

This module can be installed from [pypi](https://pypi.org/project/publicaddr/) website

```bash
pip install publicaddr
```

## Lookup

Lookup for your public IPs from random providers.

```python
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'}
```
## Get IPv4 only

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

```python
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).

```python
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.

```python
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

```bash
python3 -m unittest -v discover tests/
```
