Skip to main content

A Python STUN client for getting NAT type and external IP (RFC 3489)

Project description

py3stun

Python 3 fork of pystun

A Python STUN client for getting NAT type and external IP.

Install

python -m pip install .

Usage

$ python py3stun.py -h
# or if you install
$ py3stun.exe -h
usage: py3stun [-h] [-d] [-H STUN_HOST] [-P STUN_PORT] [-i SOURCE_IP] [-p SOURCE_PORT] [--version]

options:
  -h, --help            show this help message and exit
  -d, --debug           Enable debug logging (default: False)
  -H STUN_HOST, --stun-host STUN_HOST
                        STUN host to use (default: None)
  -P STUN_PORT, --stun-port STUN_PORT
                        STUN host port to use (default: 3478)
  -i SOURCE_IP, --source-ip SOURCE_IP
                        network interface for client (default: 0.0.0.0)
  -p SOURCE_PORT, --source-port SOURCE_PORT
                        port to listen on for client (default: 54320)
  --version             show program's version number and exit

Run

$ py3stun.exe --debug

Sample Output

2023-01-02 22:20:22,240 - pystun.get_nat_type - DEBUG - Do Test1
2023-01-02 22:20:22,240 - pystun.get_nat_type - DEBUG - Trying STUN host: stun.qq.com
2023-01-02 22:20:22,241 - pystun.stun_test - DEBUG - sendto: ('stun.qq.com', 3478)
2023-01-02 22:20:22,278 - pystun.stun_test - DEBUG - recvfrom: ('106.55.202.232', 3478)
2023-01-02 22:20:22,278 - pystun.get_nat_type - DEBUG - Result: {'Resp': True, 'ExternalIP': '111.187.111.117', 'ExternalPort': 32064, 'SourceIP': '106.55.202.232', 'SourcePort': 3478, 'ChangedIP': '106.55.201.252', 'ChangedPort': 8000}
2023-01-02 22:20:22,278 - pystun.get_nat_type - DEBUG - Do Test2
2023-01-02 22:20:22,279 - pystun.stun_test - DEBUG - sendto: ('stun.qq.com', 3478)
2023-01-02 22:20:24,290 - pystun.stun_test - DEBUG - sendto: ('stun.qq.com', 3478)
2023-01-02 22:20:26,295 - pystun.stun_test - DEBUG - sendto: ('stun.qq.com', 3478)
2023-01-02 22:20:28,308 - pystun.stun_test - DEBUG - sendto: ('stun.qq.com', 3478)
2023-01-02 22:20:30,310 - pystun.get_nat_type - DEBUG - Result: {'Resp': False, 'ExternalIP': None, 'ExternalPort': None, 'SourceIP': None, 'SourcePort': None, 'ChangedIP': None, 'ChangedPort': None}
2023-01-02 22:20:30,310 - pystun.get_nat_type - DEBUG - Do Test1
2023-01-02 22:20:30,310 - pystun.stun_test - DEBUG - sendto: ('106.55.201.252', 8000)
2023-01-02 22:20:30,348 - pystun.stun_test - DEBUG - recvfrom: ('106.55.201.252', 8000)
2023-01-02 22:20:30,348 - pystun.get_nat_type - DEBUG - Result: {'Resp': True, 'ExternalIP': '111.187.111.117', 'ExternalPort': 32065, 'SourceIP': '106.55.201.252', 'SourcePort': 8000, 'ChangedIP': '106.55.202.232', 'ChangedPort': 3478}
NAT Type: Symmetric NAT
External IP: 111.187.111.117
External Port: 32065

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

py3stun-0.1.0.tar.gz (5.0 kB view details)

Uploaded Source

Built Distribution

py3stun-0.1.0-py3-none-any.whl (5.8 kB view details)

Uploaded Python 3

File details

Details for the file py3stun-0.1.0.tar.gz.

File metadata

  • Download URL: py3stun-0.1.0.tar.gz
  • Upload date:
  • Size: 5.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.0

File hashes

Hashes for py3stun-0.1.0.tar.gz
Algorithm Hash digest
SHA256 d9bfd15f248aa28932239f876e4f60afbb0ae8e5db1c1d70440cd1112cfe99f0
MD5 f832f82e6f5b5a9147a3b2939293d051
BLAKE2b-256 f6b462d660c6bf9517d5a9123b650c3fefb70d1ae286e694797dad7b5f8a1bdd

See more details on using hashes here.

File details

Details for the file py3stun-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: py3stun-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 5.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.0

File hashes

Hashes for py3stun-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e56981c2cbbcae83e13963aeb16a3a682772f94c6d2f09f5134a7d2f9ce2581b
MD5 c989bc0c8e72d573cd5232fa6a49ed25
BLAKE2b-256 6e25326932be97c80e3661590e2a3a26e1d9a4adf824ed0dbfc87d6f1d27c5b7

See more details on using hashes here.

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