Skip to main content

pypi license

Discover external IP addresses and NAT topologies using STUN (Simple Traversal of UDP Through Network Address Translators).

PyNAT follows RFC 3489, and is inspired by a similar program for Python 2.x called PyStun. PyNAT supports Python 2.7 and later.

Installation

PyNAT requires Python 2.7 or later.

From PyPI

Install PyNAT by running pip3 install pynat from the command line.

From GitHub

Clone or download the git repo, navigate to the directory, and run:

python3 setup.py sdist
cd dist
pip3 install pynat-<version>.tar.gz

Usage

To get information about the network topology and external IP/port used, run pynat:

Network type: UDP Firewall
Internal address: 127.0.0.1:54320
External address: 127.0.0.1:54320

Run pynat -h or pynat --help for more options:

usage: pynat [-h] [--source_ip SOURCE_IP] [--source-port SOURCE_PORT]
             [--stun-host STUN_HOST] [--stun-port STUN_PORT]

PyNAT v0.0.0 Discover external IP addresses and NAT topologies using STUN.
Copyright (C) 2018 Ariel Antonitis. Licensed under the MIT License.

optional arguments:
  -h, --help            show this help message and exit
  --source_ip SOURCE_IP
                        The source IPv4/IPv6 address to bind to.
  --source-port SOURCE_PORT
                        The source port to bind to.
  --stun-host STUN_HOST
                        The STUN host to use for queries.
  --stun-port STUN_PORT
                        The port of the STUN host to use for queries.

To use PyNAT inside a Python shell or project:

from pynat import get_ip_info
topology, ext_ip, ext_port = get_ip_info()

To also get information about the internal IP, if unknown:

topology, ext_ip, ext_port, int_ip = get_ip_info(include_internal=True)

Development

PyNAT versioning functions on a MAJOR.MINOR.PATCH.[DEVELOP] model. Only stable, non development releases will be published to PyPI. Because PyNAT is still a beta project, the MAJOR increment will be 0. Minor increments represent new features. Patch increments represent problems fixed with existing features.

Release files for pynat 0.7.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pynat 0.7.0
File Size Uploaded
pynat-0.7.0.tar.gz 7.1 kB Details

Release files / pynat-0.7.0.tar.gz

Download URL pynat-0.7.0.tar.gz
Size 7.1 kB
Tags Source
SHA-256 checksum
How to use checksums
96168d472b7abc47c348cd4f6c4c1f13180bdc8c796918b1e98b4de9d0a59ede
BLAKE2b-256 checksum
How to use checksums
ffdbddaa52e3df42415231cbaf1d2f10593072cddf8317d743c5bb05fba2c2fb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.9.7

Release history Release notifications | RSS feed

This release

0.7.0 This release

1 release file

0.6.2

1 release file

0.6.1

1 release file

0.6.0

2 release files

0.5.0

2 release files

0.4.0

2 release files

0.3.0

2 release files

0.2.0

2 release files

0.1.0

2 release files

0.0.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page