Giter Site home page Giter Site logo

pystun's Introduction

PyStun

A Python STUN client for getting NAT type and external IP

This is a fork of pystun originally created by gaohawk (http://code.google.com/p/pystun/)

PyStun follows RFC 3489: http://www.ietf.org/rfc/rfc3489.txt

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

Installation

To install the latest stable version:

$ easy_install pystun

or download/clone the source and install manually using:

$ cd /path/to/pystun/src
$ python setup.py install

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

$ python setup.py develop

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

Usage

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]

Options:
  --version             show program's version number and exit
  -h, --help            show this help message and exit
  -d, --debug           Enable debug logging
  -H STUN_HOST, --host=STUN_HOST
                        STUN host to use
  -i SOURCE_IP, --interface=SOURCE_IP
                        network interface for client (default: 0.0.0.0)
  -p SOURCE_PORT, --port=SOURCE_PORT
                        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='stun.ekiga.net')

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

sip = "0.0.0.0" # 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...

LICENSE

MIT

Changelog

0.0.3 (05/21/2013)

  • Stun: fix UnboundLocalError in get_nat_type.
  • Stun: remove dead hosts from stun server list.
  • Handling get address info error.
  • Add version info to stun module and stun.cli.
  • Add MANIFEST.in and include README.rst.

pystun's People

Contributors

jtriley avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.