Python TUN/TAP tunnel module, Python3 compatible
Project description
python3-pytun
python3-pytun
is an update to the pytun
module that enables installation when using Python3. The package name was
updated for pip installation as the original appears to be abandoned. It should be a drop-in replacement (still use import pytun
.)
The patch was originally written by @famince and is available here.
Original pytun
was written by @gawen and is available here.
Original README.md
continues below.
pytun
pytun
is a Python module to manage tun/tap IP tunnel in the same way you would manipulate a file handler.
For now, it is only compatible with Linux, probably Unix, maybe MacOsX, and in the future Windows.
pytun
is under the MIT license.
How to use
First of all, clone this repos or use easy_install
or pip
.
pip install pytun
easy_install pytun
Quite easy. Use the open()
function.
import pytun
tun = pytun.open() # Open a TUN mode tunnel
For a TAP tunnel, add the "tap"
argument.
tun = pytun.open("tap")
tun
is the handler for the newly created tunnel and is manipulated like a file.
To read/write, use the standard methods recv([size = 1500])
and send(buf)
buf = tun.recv()
tun.send(buf)
tun is also select()
compatible to make your network reactor asynchronous.
import select
fds = select.select([tun, ...], [...], [...])
Finally, you can close the tunnel using the method close()
.
tun.close()
The tunnel automatically closes when the object is not referenced anymore and the garbage collector destroys the handler.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file python3-pytun-1.0.2.2.tar.gz
.
File metadata
- Download URL: python3-pytun-1.0.2.2.tar.gz
- Upload date:
- Size: 5.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 25c8906296299bd1fd16c7b432f906410c896b0ae7ef321456aa73f52e0dbae5 |
|
MD5 | 8eb4db1d94741e2ff972bf47f80dab29 |
|
BLAKE2b-256 | fe8aa5fcf11c53a44ad4ed2344048d92e5c25b77bd6cd04d71283c941c1f6692 |