Python работа с nat

Saved searches

Use saved searches to filter your results more quickly

You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.

a NAT-PMP library for Python

License

yimingliu/py-natpmp

This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

Sign In Required

Please sign in to use Codespaces.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Читайте также:  Бинарный поиск питон код

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching Xcode

If nothing happens, download Xcode and try again.

Launching Visual Studio Code

Your codespace will open once ready.

There was a problem preparing your codespace, please try again.

Latest commit

Git stats

Files

Failed to load latest commit information.

README.md

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.

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.

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 natpmp-client.py [-u] [-l lifetime] [-g gateway_addr] public_port private_port.

  • python natpmp-client.py -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 natpmp-client.py 60010 60010 Create a mapping for the public TCP port 60010 to the private TCP port 60010
  • python natpmp-client.py -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.

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.

In abstract, this little package is licensed under the new BSD license. I keep copyright on the code, but let you use it to do whatever you want, including putting it into your own software. Do not hold me responsible if things blow up — you’re the one downloading random code from the Internet.

Copyright: 2008-2023 Yiming Liu, all rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  • Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  • Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
  • The names of the author and contributors may not be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ‘AS IS’ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.»»»

About

a NAT-PMP library for Python

Источник

Saved searches

Use saved searches to filter your results more quickly

You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.

Python based Static NAT Tool

akiladananjana/Python-NAT

This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

Sign In Required

Please sign in to use Codespaces.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching Xcode

If nothing happens, download Xcode and try again.

Launching Visual Studio Code

Your codespace will open once ready.

There was a problem preparing your codespace, please try again.

Latest commit

Git stats

Files

Failed to load latest commit information.

README.md

Python based Static NAT Tool

Static NAT maps network traffic from a static external IP address to an internal IP address or network. It creates a static translation of real addresses to mapped addresses. To execute this utility you need to have Ubuntu box with two NICs. NAT translations are happens between these interfaces.

python3 Inside-Local-IP> Inside-Global-IP>

Inside-Local-IP = The IP address of the device in Inside Network.

Inside-Global-IP = The IP address of the outside interface.

Tested with Ubuntu 20.04 with Python 3.8.2

This utility only works with ICMP traffic because of I alter the TCP/UDP headers. Then TCP/UDP checksum validation fails. Also I hardcoded the ens33 and ens38 interfaces, change them to yours.

About

Python based Static NAT Tool

Источник

Saved searches

Use saved searches to filter your results more quickly

You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.

A Python STUN client for getting NAT type and external IP

License

jtriley/pystun

This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

Sign In Required

Please sign in to use Codespaces.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching Xcode

If nothing happens, download Xcode and try again.

Launching Visual Studio Code

Your codespace will open once ready.

There was a problem preparing your codespace, please try again.

Latest commit

Git stats

Files

Failed to load latest commit information.

README.rst

https://coveralls.io/repos/jtriley/pystun/badge.png

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/)

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

To install the latest version:

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:

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

$ pystun NAT Type: Full Cone External IP: External Port: 54320

Pass —help for more options:

% pystun --help usage: pystun [-h] [-d] [-H STUN_HOST] [-P STUN_PORT] [-i SOURCE_IP] [-p SOURCE_PORT] [--version] optional arguments: -h, --help show this help message and exit -d, --debug Enable debug logging (default: False) -H STUN_HOST, --host STUN_HOST STUN host to use (default: None) -P STUN_PORT, --host-port STUN_PORT STUN host port to use (default: 3478) -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) --version show program's version number and exit
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')

If you prefer to use a specific STUN server port:

nat_type, external_ip, external_port = stun.get_ip_info(stun_port=3478)

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.

Источник

pystun3 1.0.0

A Python STUN client for getting NAT type and external IP. Supports Python versions 2 and 3.

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

Installation

To install the latest version:

or download/clone the source and install manually using:

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

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

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

Usage

$ pystun3 NAT Type: Full Cone External IP: External Port: 54320

Pass –help for more options:

% pystun3 --help usage: pystun3 [-h] [-d] [-H STUN_HOST] [-P STUN_PORT] [-i SOURCE_IP] [-p SOURCE_PORT] [--version] optional arguments: -h, --help show this help message and exit -d, --debug Enable debug logging (default: False) -H STUN_HOST, --host STUN_HOST STUN host to use (default: None) -P STUN_PORT, --host-port STUN_PORT STUN host port to use (default: 3478) -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) --version show program's version number and exit
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')

If you prefer to use a specific STUN server port:

nat_type, external_ip, external_port = stun.get_ip_info(stun_port=3478)

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…

Источник

Оцените статью