Skip to main content

Linux TUN/TAP wrapper for Python

Project description

pytun is a Python module which let you create TUN/TAP device very easily.

License: MIT (see LICENSE)

Installation and Dependencies

Install pytun with pip install python-pytun or download this archive, decompress it and execute python setup.py install. As pytun is a C module you will need a compiler (e.g GCC) and the Python developpement headers installed on your system (e.g on Debian-like distribution check that build-essential and python-dev are present). There are no dependencies other than the Python Standard Library.

Examples

NOTE: On most distributions you will need to be root to run these examples.

To create a TUN device:

from pytun import TunTapDevice

tun = TunTapDevice()

To create a TAP device:

from pytun import TunTapDevice, IFF_TAP

tap = TunTapDevice(flags=IFF_TAP)

To create a TUN/TAP device with a custom name use the name keyword:

tun = TunTapDevice(name='mytun')

You can get/set some parameters of the device directly:

print tun.name
tun.addr = '10.8.0.1'
tun.dstaddr = '10.8.0.2'
tun.netmask = '255.255.255.0'
tun.mtu = 1500

To read/write to the device, use the methods read(size) and write(buf):

buf = tun.read(tun.mtu)
tun.write(buf)

When when you are done with a device, close it:

tun.close()

You can also use TunTapDevice objects with all functions that expect a fileno() method (e.g select())

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

python-pytun-0.2.tar.gz (6.7 kB view details)

Uploaded Source

File details

Details for the file python-pytun-0.2.tar.gz.

File metadata

  • Download URL: python-pytun-0.2.tar.gz
  • Upload date:
  • Size: 6.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for python-pytun-0.2.tar.gz
Algorithm Hash digest
SHA256 d02ad66372b4edf73e1fb1a34d2610a49d359a56e081585dffd3290322c6b9d1
MD5 0c8ce8ace5046e4a219f9d8b304c0117
BLAKE2b-256 3ac66792ce3b89260d3b30eef6cd8b36122064a301c971264bf04c2f9991cdd1

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page