LinuxCommandLibrary

pystun3

Determine public IP address and NAT type

TLDR

Make a STUN request

$ pystun3
copy

Make a STUN request and specify the stun server
$ pystun3 --stun-host [stun.1und1.de]
copy

Make a STUN request and specify the source port
$ pystun3 --source-port [7932]
copy

SYNOPSIS

pystun3 [-h] [-H HOST] [-P PORT] [-i INTERVAL] [-d DURATION] [-v]

PARAMETERS

-h, --help
    Displays the help message and exits, providing comprehensive information about the command-line options and usage.

-H HOST, --host HOST
    Specifies the hostname or IP address of the STUN server to query. If omitted, it defaults to stun.l.google.com.

-P PORT, --port PORT
    Defines the port number of the STUN server. The standard STUN port is 19302, which is used by default if no port is specified.

-i INTERVAL, --interval INTERVAL
    Sets the interval in seconds between successive queries when the command is run for a specific duration. The default interval is 1 second.

-d DURATION, --duration DURATION
    Determines the total time in seconds for which pystun3 should query the STUN server. A value of 0 indicates that the command should run once and then exit. The default value is 0.

-v, --verbose
    Enables verbose output, providing more detailed information about the STUN query process, including sent requests and received responses.

DESCRIPTION

pystun3 is a command-line tool and Python library designed for interacting with STUN (Session Traversal Utilities for NAT) servers. Its primary function is to help users determine their public IP address and the specific type of NAT (Network Address Translator) they are behind. This capability is crucial for establishing direct peer-to-peer connections in various real-time communication applications such as VoIP (Voice over IP) and WebRTC, especially when clients are located behind different or complex NAT configurations.

The tool operates by sending STUN binding requests to a designated STUN server and then meticulously analyzing the responses to deduce the network's topology and the client's accessible IP information. It is highly valuable for network diagnostics, testing firewall configurations, and ensuring robust connectivity for applications that necessitate direct peer-to-peer communication across diverse network environments.

CAVEATS

pystun3's functionality is dependent on the availability and proper operation of the external STUN servers it queries. Network environments with strict firewalls or specific security policies may block STUN traffic, which could prevent the tool from accurately determining NAT information. While it can identify common NAT types (e.g., Full Cone, Restricted Cone, Port Restricted Cone, Symmetric NAT), it may not provide exhaustive details for highly complex or non-standard network configurations.

HISTORY

The pystun project, the precursor to pystun3, emerged as an open-source Python implementation of a STUN client. pystun3 specifically denotes its compatibility and development target for Python 3 environments, distinguishing it from earlier Python 2-based versions. It was created to address the need for a lightweight and easily scriptable STUN client, particularly for developers working on applications involving VoIP, WebRTC, and other peer-to-peer communication protocols that necessitate NAT traversal capabilities. Its ongoing development focuses on maintaining a simple, functional, and reliable STUN binding request mechanism.

SEE ALSO

nc(1), netcat(1), dig(1), nmap(1)

Copied to clipboard