![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 with IPv4 and IPv6:
- [x] Google (DNS & HTTP & STUN)
- [x] Cloudflare (DNS & HTTP)
- [x] OpenDNS (DNS)
- [x] Akamai (DNS & HTTP)
- [x] [Ipify](https://www.ipify.org/) (HTTP)
- [x] Icanhazip (HTTP)
- [x] [Matrix](https://www.matrix.org) (STUN)
- [x] [Framasoft](https://framasoft.org/) (STUN)
- [x] [Ifconfig.me](https://ifconfig.me/) (HTTP)
## Installation
![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 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.
```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'}
```
## 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.MULLVAD` *(disabled by default in config because IPv6 is not supported)*
- `publicaddr.IFCONFIG_ME`
## Custom configuration
See the default [configuration file](../main/publicaddr/publicaddr.yml)
## 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
```
### 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/4d/d4/63b5e6f4fe20fee2432de1c102e9c830bef7ff3f432b72f73dbb84f2acea/publicaddr-0.14.2.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 with IPv4 and IPv6:\n\n- [x] Google (DNS & HTTP & STUN)\n- [x] Cloudflare (DNS & HTTP)\n- [x] OpenDNS (DNS)\n- [x] Akamai (DNS & HTTP)\n- [x] [Ipify](https://www.ipify.org/) (HTTP)\n- [x] Icanhazip (HTTP)\n- [x] [Matrix](https://www.matrix.org) (STUN)\n- [x] [Framasoft](https://framasoft.org/) (STUN)\n- [x] [Ifconfig.me](https://ifconfig.me/) (HTTP)\n\n## Installation\n\n![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 v6\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## 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.MULLVAD` *(disabled by default in config because IPv6 is not supported)*\n- `publicaddr.IFCONFIG_ME`\n\n## Custom configuration\n\nSee the default [configuration file](../main/publicaddr/publicaddr.yml)\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### 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.14.2",
"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": "ad66da2ec2e5d5f170b6a2a921aca606af13f4a9dabab7317cc633b46affea81",
"md5": "fa5acc340fcdb09b1fad4fdedf31afdd",
"sha256": "91cbf183d2d6c7c761f791da9733c75921eaf99e4bce6a62087ae2667be3afca"
},
"downloads": -1,
"filename": "publicaddr-0.14.2-py3-none-any.whl",
"has_sig": false,
"md5_digest": "fa5acc340fcdb09b1fad4fdedf31afdd",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 10539,
"upload_time": "2024-07-15T07:08:59",
"upload_time_iso_8601": "2024-07-15T07:08:59.378863Z",
"url": "https://files.pythonhosted.org/packages/ad/66/da2ec2e5d5f170b6a2a921aca606af13f4a9dabab7317cc633b46affea81/publicaddr-0.14.2-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "4dd463b5e6f4fe20fee2432de1c102e9c830bef7ff3f432b72f73dbb84f2acea",
"md5": "024157bbb92ae835a796b0faa4c5d5f3",
"sha256": "31ac3397c98cb3dd9d80c88328d0346fd6d73149debdc3a37b9a652880be617b"
},
"downloads": -1,
"filename": "publicaddr-0.14.2.tar.gz",
"has_sig": false,
"md5_digest": "024157bbb92ae835a796b0faa4c5d5f3",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 8864,
"upload_time": "2024-07-15T07:09:04",
"upload_time_iso_8601": "2024-07-15T07:09:04.773088Z",
"url": "https://files.pythonhosted.org/packages/4d/d4/63b5e6f4fe20fee2432de1c102e9c830bef7ff3f432b72f73dbb84f2acea/publicaddr-0.14.2.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-07-15 07:09:04",
"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.6.1"
]
]
},
{
"name": "aiostun",
"specs": [
[
"==",
"0.4.1"
]
]
},
{
"name": "pyyaml",
"specs": [
[
"==",
"6.0.1"
]
]
}
],
"lcname": "publicaddr"
}