publicaddr


Namepublicaddr JSON
Version 0.16.0 PyPI version JSON
download
home_pagehttps://github.com/dmachard/python-publicaddr
SummaryGetting your public IP v4 and v6
upload_time2024-11-11 17:35:28
maintainerNone
docs_urlNone
authorDenis MACHARD
requires_pythonNone
licenseNone
keywords public ip dns http google akamai opendns cloudflare
VCS
bugtrack_url
requirements requests dnspython aiostun pyyaml checkifvalid
Travis-CI No Travis.
coveralls test coverage No coveralls.
            ![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)

# What is this?

[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)

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                                     |
|--------------|-------|------|-----|------|------|------------------------------------------------|
| google       |  ❌   |   ✔️  |  ✔️  |  ✔️   |  ✔️   |                                                |
| cloudflare   |  ✔️    |  ❌  |  ✔️  |  ✔️   |  ✔️   |                                                |
| openDNS      |  ❌   |  ❌  |  ✔️  |  ✔️   |  ✔️   |                                                |
| akamai       |  ✔️    |  ❌  |  ✔️  |  ✔️   |  ✔️   |                                                |
| ipify        |  ✔️    |  ❌  |  ❌ |  ✔️   |  ✔️   |                                                |
| icanhazip    |  ✔️    |  ❌  |  ❌ |  ✔️   |  ✔️   |                                                |
| matrix       |  ❌   |  ✔️   |  ❌ |  ✔️   |  ✔️   |                                                |
| framasoft    |  ❌   |  ✔️   |  ❌ |  ✔️   |  ✔️   |                                                |
| ifconfig.me  |  ✔️   |  ❌   |  ❌ |  ✔️   |  ✔️   |                                                |

## Installation

![python 3.13.x](https://img.shields.io/badge/python%203.13.x-tested-blue) ![python 3.12.x](https://img.shields.io/badge/python%203.12.x-tested-blue) ![python 3.11.x](https://img.shields.io/badge/python%203.11.x-tested-blue) ![python 3.10.x](https://img.shields.io/badge/python%203.10.x-tested-blue)

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

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

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

## 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.

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

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

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

```bash
sudo apt install python3-venv
python3 -m venv venv
source venv/bin/activate
```

```bash
python3 -m pip install -r requirements.txt
python3 example.py
```

### Custom configuration

See the default [configuration file](../main/publicaddr/publicaddr.yml)

### Run test units

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

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/dmachard/python-publicaddr",
    "name": "publicaddr",
    "maintainer": null,
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": null,
    "keywords": "public ip dns http google akamai opendns cloudflare",
    "author": "Denis MACHARD",
    "author_email": "d.machard@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/66/9b/641ae20f9427a5616a4ffe07f942b784138d345ddc97984750fa5c01cde5/publicaddr-0.16.0.tar.gz",
    "platform": "any",
    "description": "![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)\n\n# What is this?\n\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n\nSimple python module for getting your **public IP V4 and V6** from several providers in **random** mode with also several protocols (DNS, HTTPS and STUN).\n\nSupported providers\n\n| IP Checker   | HTTPS | STUN | DNS | IPv4 | IPv6 | Use Policy                                     |\n|--------------|-------|------|-----|------|------|------------------------------------------------|\n| google       |  \u274c   |   \u2714\ufe0f  |  \u2714\ufe0f  |  \u2714\ufe0f   |  \u2714\ufe0f   |                                                |\n| cloudflare   |  \u2714\ufe0f    |  \u274c  |  \u2714\ufe0f  |  \u2714\ufe0f   |  \u2714\ufe0f   |                                                |\n| openDNS      |  \u274c   |  \u274c  |  \u2714\ufe0f  |  \u2714\ufe0f   |  \u2714\ufe0f   |                                                |\n| akamai       |  \u2714\ufe0f    |  \u274c  |  \u2714\ufe0f  |  \u2714\ufe0f   |  \u2714\ufe0f   |                                                |\n| ipify        |  \u2714\ufe0f    |  \u274c  |  \u274c |  \u2714\ufe0f   |  \u2714\ufe0f   |                                                |\n| icanhazip    |  \u2714\ufe0f    |  \u274c  |  \u274c |  \u2714\ufe0f   |  \u2714\ufe0f   |                                                |\n| matrix       |  \u274c   |  \u2714\ufe0f   |  \u274c |  \u2714\ufe0f   |  \u2714\ufe0f   |                                                |\n| framasoft    |  \u274c   |  \u2714\ufe0f   |  \u274c |  \u2714\ufe0f   |  \u2714\ufe0f   |                                                |\n| ifconfig.me  |  \u2714\ufe0f   |  \u274c   |  \u274c |  \u2714\ufe0f   |  \u2714\ufe0f   |                                                |\n\n## Installation\n\n![python 3.13.x](https://img.shields.io/badge/python%203.13.x-tested-blue) ![python 3.12.x](https://img.shields.io/badge/python%203.12.x-tested-blue) ![python 3.11.x](https://img.shields.io/badge/python%203.11.x-tested-blue) ![python 3.10.x](https://img.shields.io/badge/python%203.10.x-tested-blue)\n\nThis module can be installed from [pypi](https://pypi.org/project/publicaddr/) website\n\n```bash\npip install publicaddr\n```\n\n## Lookup for IPv4 and IPv6\n\nLookup for your public IPs from random providers with DNS or HTTP protocols with 3 retries if no ips are returned.\nThis is the default behaviour of the `lookup` function.\n\n```python\nimport publicaddr\n\npublicaddr.lookup()\n{'ip4': 'x.x.x.x', 'ip6': 'x:x:x:x:x:x:x:x', 'provider': 'opendns',\n'proto': 'dns', 'duration': '0.037'}\n```\n\n## Configuration\n\nThis module can be configurated with environment variables\n| Variables | Description |\n| ------------- | ------------- |\n| PUBLICADDR_DEBUG | debug mode 1 or 0 |\n| PUBLICADDR_TIMEOUT | timeout, default is 2s |\n| PUBLICADDR_RETRIES | retries, default is 3|\n| PUBLICADDR_IPV6_ENABLED | enable ipv6 with 1 or 0 to disable |\n| PUBLICADDR_LOOKUP_HTTPS | lookup with HTTPS protocol  (1 or 0 to disable) |\n| PUBLICADDR_LOOKUP_DNS | lookup with DNS protocol  (1 or 0 to disable) |\n| PUBLICADDR_LOOKUP_STUN | lookup with STUN protocol  (1 or 0 to disable) |\n\n\n## Specific lookups\n\n### Lookup for public IP with specific protocol\n\nLookup for your public IPs from random DNS providers with specific protocol.\n\n```python\nimport publicaddr\n\npublicaddr.lookup(providers=publicaddr.DNS, retries=2)\n{'ip4': 'x.x.x.x', 'ip6': 'x:x:x:x:x:x:x:x', 'provider': 'opendns',\n'proto': 'dns', 'duration': '0.037'}\n```\n\nDefault constants for transport protocol:\n\n- `publicaddr.HTTPS`\n- `publicaddr.DNS`\n- `publicaddr.STUN`\n\n### Get IPv4 or IPv6 only\n\nGet your public IPv4 with default provider (Google with DNS protocol).\n\n```python\nimport publicaddr\n\npublicaddr.get(ip=publicaddr.IPv4)\n{'ip': 'x.x.x.x', 'duration': '0.025'}\n```\n\nDefault constants for IP version:\n\n- `publicaddr.IPv4`\n- `publicaddr.IPv6`\n\n### Get IP with specific provider\n\nExample to use the provider Cloudflare instead of the default one.\n\n```python\nimport publicaddr\n\nmyip = publicaddr.get(provider=publicaddr.CLOUDFLARE, proto=publicaddr.DNS)\n{'ip': 'x:x:x:x:x:x:x:x', 'duration': '0.020'}\n```\n\nDefault constants for providers:\n\n- `publicaddr.CLOUDFLARE`\n- `publicaddr.GOOGLE`\n- `publicaddr.OPENDNS`\n- `publicaddr.AKAMAI`\n- `publicaddr.IPIFY`\n- `publicaddr.ICANHAZIP`\n- `publicaddr.MATRIX`\n- `publicaddr.FRAMASOFT`\n- `publicaddr.IFCONFIG_ME`\n\n## For developpers\n\n### Run from source\n\n```bash\nsudo apt install python3-venv\npython3 -m venv venv\nsource venv/bin/activate\n```\n\n```bash\npython3 -m pip install -r requirements.txt\npython3 example.py\n```\n\n### Custom configuration\n\nSee the default [configuration file](../main/publicaddr/publicaddr.yml)\n\n### Run test units\n\n```bash\npython3 -m unittest discover tests/\n```\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "Getting your public IP v4 and v6",
    "version": "0.16.0",
    "project_urls": {
        "Homepage": "https://github.com/dmachard/python-publicaddr"
    },
    "split_keywords": [
        "public",
        "ip",
        "dns",
        "http",
        "google",
        "akamai",
        "opendns",
        "cloudflare"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "2216ee56f4ef56eebe3305598661aa7fbba77407f35bd3bd6c6bb574dfbef561",
                "md5": "0f8454ab54d3319d179b8145a800f293",
                "sha256": "7a6bb546137139508974196301a99c12e1c57b2324587b06cde36548066fff6a"
            },
            "downloads": -1,
            "filename": "publicaddr-0.16.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "0f8454ab54d3319d179b8145a800f293",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 16472,
            "upload_time": "2024-11-11T17:35:26",
            "upload_time_iso_8601": "2024-11-11T17:35:26.654888Z",
            "url": "https://files.pythonhosted.org/packages/22/16/ee56f4ef56eebe3305598661aa7fbba77407f35bd3bd6c6bb574dfbef561/publicaddr-0.16.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "669b641ae20f9427a5616a4ffe07f942b784138d345ddc97984750fa5c01cde5",
                "md5": "48e38d04d2c818c100d9948a17a7c2ff",
                "sha256": "35eb8d1c4e90f53aea3130d28a33cd2ae16c263bfb645f0ba3d49bde2315950b"
            },
            "downloads": -1,
            "filename": "publicaddr-0.16.0.tar.gz",
            "has_sig": false,
            "md5_digest": "48e38d04d2c818c100d9948a17a7c2ff",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 10590,
            "upload_time": "2024-11-11T17:35:28",
            "upload_time_iso_8601": "2024-11-11T17:35:28.621257Z",
            "url": "https://files.pythonhosted.org/packages/66/9b/641ae20f9427a5616a4ffe07f942b784138d345ddc97984750fa5c01cde5/publicaddr-0.16.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-11-11 17:35:28",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "dmachard",
    "github_project": "python-publicaddr",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [
        {
            "name": "requests",
            "specs": [
                [
                    "==",
                    "2.32.3"
                ]
            ]
        },
        {
            "name": "dnspython",
            "specs": [
                [
                    "==",
                    "2.7.0"
                ]
            ]
        },
        {
            "name": "aiostun",
            "specs": [
                [
                    "==",
                    "0.4.1"
                ]
            ]
        },
        {
            "name": "pyyaml",
            "specs": [
                [
                    "==",
                    "6.0.2"
                ]
            ]
        },
        {
            "name": "checkifvalid",
            "specs": [
                [
                    "==",
                    "0.1.1"
                ]
            ]
        }
    ],
    "lcname": "publicaddr"
}
        
Elapsed time: 0.60148s