skip to navigation
skip to content

Not Logged In

pystun 0.0.2

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

Latest Version: 0.1.0

A Python STUN client for getting NAT type and external IP

This is a fork of pystun originally created by gaohawk (

PyStun follows RFC 3489:

A server following STUN-bis hasn’t been found on internet so RFC3489 is the only implementation.


To install the latest stable version:

$ easy_install pystun

or download/clone the source and install manually using:

$ cd /path/to/pystun/src
$ python install

If you’re hacking on pystun you should use the ‘develop’ command instead:

$ python develop

This will make a link to the sources inside your site-packages directory so that any changes are immediately available for testing.


From command line:

$ pystun
NAT Type: Full Cone
External IP: <your-ip-here>
External Port: 54320

Pass –help for more options:

% pystun --help
Usage: pystun [options]

  -h, --help            show this help message and exit
  -d, --debug           Enable debug logging
                        STUN host to use
  -i SOURCE_IP, --interface=SOURCE_IP
                        network interface for client (default:
                        port to listen on for client (default: 54320)

From Python:

import stun
nat_type, external_ip, external_port = stun.get_ip_info()

This will rotate through an internal list of STUN servers until a response is found. If no response is found you will get “Blocked” as the nat_type and None for external_ip and external_port.

If you prefer to use a specific STUN server:

nat_type, external_ip, external_port = stun.get_ip_info(stun_host='')

You may also specify the client interface and port that is used although this is not needed:

sip = "" # interface to listen on (all)
port = 54320 # port to listen on
nat_type, external_ip, external_port = stun.get_ip_info(sip, port)

Read the code for more details…



File Type Py Version Uploaded on Size
pystun-0.0.2.tar.gz (md5) Source 2011-09-20 5KB
  • Downloads (All Versions):
  • 14 downloads in the last day
  • 188 downloads in the last week
  • 639 downloads in the last month