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 .
or
python -m pip install py3stun
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
Release history Release notifications | RSS feed
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.1.tar.gz
(5.8 kB
view details)
Built Distribution
File details
Details for the file py3stun-0.1.1.tar.gz
.
File metadata
- Download URL: py3stun-0.1.1.tar.gz
- Upload date:
- Size: 5.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a398979d9ee87e5af8679818be0f908971ec03165e888fd3d67add2374d2e315 |
|
MD5 | 14fd4322b127db2994c44ae401f2d36d |
|
BLAKE2b-256 | 845d6bf1fb9d090e832888d5de5a7d0fc01c67f5d28fe70d78dad201a253f708 |
File details
Details for the file py3stun-0.1.1-py3-none-any.whl
.
File metadata
- Download URL: py3stun-0.1.1-py3-none-any.whl
- Upload date:
- Size: 6.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1e188321d341f8f2fc9302f070ceb749f72423abee15b3bbc4589db8be2f6180 |
|
MD5 | ca268b090a4f7a023b0b8880f1d1f4f3 |
|
BLAKE2b-256 | e1a2b0c4128ac569ddb7cfd151ac7db08a8bf8d8939eb74f0af8e6391f714dbc |