Skip to main content

Python classes for interacting with NAT-PMP v0

Project description

https://img.shields.io/pypi/v/NAT-PMP.svg https://img.shields.io/pypi/pyversions/NAT-PMP.svg tests Code style: Black

Provides functions to interact with NAT-PMP gateways implementing version 0 of the NAT-PMP draft specification.

Forked from py-natpmp by Yiming Liu. See this blog for more background.

Introduction

py-natpmp is a NAT-PMP (Network Address Translation Port Mapping Protocol) library and testing client in Python. The client allows you to set up dynamic port mappings on NAT-PMP compatible routers. Thus this is a means for dynamic NAT traversal with routers that talk NAT-PMP. In practical terms, this is basically limited to the newer Apple AirPort base stations and the AirPort Express, which have support for this protocol.

In any case, this library puts a thin layer of Python abstraction over the NAT-PMP protocol, version 0, as specified by the NAT-PMP draft standard.

Library

The library provides a set of high-level and low-level functions to interact via the NAT-PMP protocol. The functions map_port and get_public_address provide the two high-level functions offered by NAT-PMP. Responses are stored as Python objects.

Client

To use the client, grab it and the above library. Make sure you have the library in the same directory as the client script or otherwise on your Python instance’s sys.path. Invoke the client on the command-line (Terminal.app) as python -m natpmp [-u] [-l lifetime] [-g gateway_addr] public_port private_port.

For example:

python -m natpmp -u -l 1800 60009 60009 Create a mapping for the public UDP port 60009 to the private UDP port 60009 for 1,800 seconds (30 minutes)

python -m natpmp 60010 60010 Create a mapping for the public TCP port 60010 to the private TCP port 60010

python -m natpmp -g 10.0.1.1 60011 60022 Explicitly instruct the gateway router 10.0.1.1 to create the TCP mapping from 60010 to 60022

Remember to turn off your firewall for those ports that you map.

Caveats

This is an incomplete implementation of the specification. When the router reboots, all dynamic mappings are lost. The specification provides for notification packets to be sent by the router to each client when this happens. There is no support in this library and client to monitor for such notifications, nor does it implement a daemon process to do so. The specification recommends queuing requests – that is, all NAT-PMP interactions should happen serially. This simple library does not queue requests – if you abuse it with multithreading, it will send those requests in parallel and possibly overwhelm the router.

The library will attempt to auto-detect your NAT gateway. This is done via a popen to netstat on BSDs/Darwin and ip on Linux. This is likely to fail miserably, depending on how standard the output is. In the library, a keyword argument is provided to override the default and specify your own gateway address. In the client, use the -g switch to manually specify your gateway.

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

NAT-PMP-1.3.2.tar.gz (15.7 kB view details)

Uploaded Source

Built Distribution

NAT_PMP-1.3.2-py3-none-any.whl (8.4 kB view details)

Uploaded Python 3

File details

Details for the file NAT-PMP-1.3.2.tar.gz.

File metadata

  • Download URL: NAT-PMP-1.3.2.tar.gz
  • Upload date:
  • Size: 15.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.7.3 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.9.2

File hashes

Hashes for NAT-PMP-1.3.2.tar.gz
Algorithm Hash digest
SHA256 545773876dbcdc604dc5d117211468297c44b67ac1eb2aecacf62459be0730b6
MD5 7e5faa22acb0935f75664e9c4941fda4
BLAKE2b-256 dc0c28263fb4a623e6718a179bca1f360a6ae38f0f716a6cacdf47e15a5fa23e

See more details on using hashes here.

File details

Details for the file NAT_PMP-1.3.2-py3-none-any.whl.

File metadata

  • Download URL: NAT_PMP-1.3.2-py3-none-any.whl
  • Upload date:
  • Size: 8.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.7.3 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.9.2

File hashes

Hashes for NAT_PMP-1.3.2-py3-none-any.whl
Algorithm Hash digest
SHA256 b53fa5923ebf64a4d4db5c99851014f74cda34f11494f5741ab23a03a831dfdf
MD5 49004bae14fc003be23538264a1d25aa
BLAKE2b-256 d99fd7392c050c8a59aeb1ec011cbd30e6a007b9f2398feeb66676e2ba9b7330

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