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.
Documentation
NOTE: On most distributions you will need to be root to create TUN/TAP devices.
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
If the device is a TAP you can also get/set its MAC address:
tap.hwaddr = '\x00\x11\x22\x33\x44\x55' print tap.hwaddr
To make the device persistent:
tun.persist(True)
To bring up the device:
tun.up()
To bring down the device:
tun.down()
To enable/disable the queue associated with the device (works only if it has been created with IFF_MULTI_QUEUE):
tun.mq_attach() # enable the queue tun.mq_attach(False) # disable the queue
To read/write to the device, use the methods read(size) and write(buf):
buf = tun.read(tun.mtu) tun.write(buf)
To close the device:
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
Built Distributions
Hashes for python_pytun-2.4.1-cp311-cp311-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 029b831a17184b93639f485ae73f13c78db9e87af59d620f19cc8d339be1e1bc |
|
MD5 | 991a2ec49120b33e408175f1ff20f2cd |
|
BLAKE2b-256 | 49ab03407d8010438cfdc819560359fe1f76115be27b1179f910f3a70cf4155e |
Hashes for python_pytun-2.4.1-cp311-cp311-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fdf1db07ea00bb1fe9dd2237054122a80a2684195edd7fa497d6beffbfe8a8d8 |
|
MD5 | 6b6b6fdf9e749ab0e6585f2d279cd80d |
|
BLAKE2b-256 | f52de42c9392cc6960eae1fc807763b2e11d98555ae30653476aea4a619cb54d |
Hashes for python_pytun-2.4.1-cp310-cp310-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 32c7c06467653f308359e36c429040918873211b3cc0488f28790156bdb19cf3 |
|
MD5 | e2e0b00706aeafec3cb5721b36fd0479 |
|
BLAKE2b-256 | e438e047b91fdd1941a8b8f39666dceabc70994260c0e694aac0fff710c969dd |
Hashes for python_pytun-2.4.1-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ce28e8b17bf6af24ed9adf06d126bf14cf29a2c768fe7cdc432cf89bc926f4ed |
|
MD5 | b7d2072903e5ee70d308adf1b1efa70d |
|
BLAKE2b-256 | 1a9d107c54856dff3a1d879126b659b1c187d12bcc30cdc79c0f393f0f6b1e91 |
Hashes for python_pytun-2.4.1-cp39-cp39-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c0300d07321c9a9174ac6345dc2e37563b0ed7f708abd5f72aeafce989ba8a6e |
|
MD5 | 1329050b988817df193c7cd88cddf3e5 |
|
BLAKE2b-256 | dd6d97499ca661030ba003f26044005fe4bace6d0cf6974c366e141e7f565286 |
Hashes for python_pytun-2.4.1-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | dff659c2a4bcdf51e72593f4373ed0bca4535d657e325845c7b20499f84de946 |
|
MD5 | 003b84868ed2cf86996a60efff573507 |
|
BLAKE2b-256 | 8b4199ac3e06ec7a041b9859e6a691b24865c1716312bd91f0a31fe425bea4cc |
Hashes for python_pytun-2.4.1-cp39-cp39-manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cf71a416ef2d5836b409fc9f6a35072343d0e46372bb001a55ce21df6479e148 |
|
MD5 | a6254d4ce0ca456c40a9acd3c1e1e0c3 |
|
BLAKE2b-256 | d3d8ff10c686e55a0b2e7f89d08281515b18232271524ab75181f5a51b48feca |
Hashes for python_pytun-2.4.1-cp39-cp39-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1bba06f87cf49dd226907c5fcdfab86edd427027cd863b47b69c9ba863b81428 |
|
MD5 | 15953d1e5c1cb4c0c2f84c34142bc376 |
|
BLAKE2b-256 | 26bb4d533936a49a0b3b12993c08e640fc37b7227cb7580f38fc8afc09667397 |
Hashes for python_pytun-2.4.1-cp38-cp38-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2fbbbe30b3c3d5ed87e8db7e9ff521123844096b5e71ceab90e3c45b423ff7b6 |
|
MD5 | 14bd0fc078f0355d7ad27a117c7cb809 |
|
BLAKE2b-256 | a9fcaf2b7ffc17effee1eea5fa484cdcf3f6085983c17c82f9b63eae3c6b4134 |
Hashes for python_pytun-2.4.1-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b7be32f99adc656a91e810c6a6cbfda0001b55f64d3671cbe9376f98a33cd02b |
|
MD5 | 304ed6f2d65557af8ec8be637a648a0a |
|
BLAKE2b-256 | 452a574d9630a5da26b1d50a739c1cd92ccc8baaebde38b5648e54b803e5f394 |
Hashes for python_pytun-2.4.1-cp38-cp38-manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7fe69665812eca121ad67d7cad0fc0188e0a8e9ada13b2160fd72599eb9d6785 |
|
MD5 | 98f6c1b95f381c3f446463b6da9a32e2 |
|
BLAKE2b-256 | 2935ba54b4c6aac9fcaee7b7275fb769ddb7143b01b17c0cf9aeb72b36648a3c |
Hashes for python_pytun-2.4.1-cp38-cp38-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 290ccface53aac4978b3d6318b63cef40218f9cb2d3d8d31e23360e378a60d89 |
|
MD5 | e02ee4f16de8376491384e25a09604c3 |
|
BLAKE2b-256 | fde297be63607c85d6aaa88fd42cd8a7ede7eaa5a61def6431ed22994eefdcaf |
Hashes for python_pytun-2.4.1-cp37-cp37m-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a635cf1ce6954062d98e153d8ab13fc1f46b8c020b49c6d3d148c5f6bd9bc7ef |
|
MD5 | e163d11c59c757f744c27a34d613ee0b |
|
BLAKE2b-256 | df27122f29a42c88f3ddff0a2734e044f7c483af3feba5970e2a0d3649a33b63 |
Hashes for python_pytun-2.4.1-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f220e52e870082f17a169689dc1527bb2deab04e7b922f4d7092ddd908a51151 |
|
MD5 | 276a4598a9b14c5967da2878e2e13a09 |
|
BLAKE2b-256 | 33627699da0923a2078cf7d4e078cca935d29ee6fd04b764b4b55705b8b31c3a |
Hashes for python_pytun-2.4.1-cp37-cp37m-manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e13ae10c2e4d7ca9d9993b1d448c70e1fdbea000b016a9ac9064fdcc498fbd9a |
|
MD5 | b20a920adfee73688d211c85d505c643 |
|
BLAKE2b-256 | fd2aa8f18e47a278b49b4f2549107a3c8427f28b71d7d96162729a42d3b38df4 |
Hashes for python_pytun-2.4.1-cp37-cp37m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 47fbf0eacc1a3f77ceeb632596c8d9cc39a7f6235a710aa7b970577b09d0194d |
|
MD5 | 06eca3f29d6e34b87b7d389c5f2f2e9a |
|
BLAKE2b-256 | 0bf1c6c6e71d4ffae4c0c49ceb45493455020aa56c974bfb47536db29f8ae09b |
Hashes for python_pytun-2.4.1-cp36-cp36m-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f47f596d89cc2a51e74dfa99759320414b38a4165102fdf5c8fcba25423ed433 |
|
MD5 | 7d093b585ff51018c6d4844686668338 |
|
BLAKE2b-256 | c12261e16a75846c68dccc02b851a4fe37b0f15acb06c7b5abcf507403d9d2a0 |
Hashes for python_pytun-2.4.1-cp36-cp36m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 00e95d50a0e99c3e425041aa312adafb81defda056d4f1769468a32d40aa2360 |
|
MD5 | 855bb5f43b0454908b16ae685e1a29f4 |
|
BLAKE2b-256 | 6dcdbf9cf1817ad3d151b2601acc5d11bdccfdecfd1020657994eef9b811669f |
Hashes for python_pytun-2.4.1-cp36-cp36m-manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f087c6301d17363356c2d23073e47d3e5abd9a49df9550fefd4759fc62fac0bd |
|
MD5 | e8c6d9bc460f3dc2d043f4c8a8b67b53 |
|
BLAKE2b-256 | 24362678acdc83c4d25e21584714137cf8e0dc77d96808c879722aff9246faaa |
Hashes for python_pytun-2.4.1-cp36-cp36m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 831576ba1ba9d4b02c2af1825aec031d3e79a0d6e27a691a8348cbe6c9cb17b5 |
|
MD5 | 13ee561217add85962c32a4d6e0dc3ae |
|
BLAKE2b-256 | 8749f17cb763a8febd3132094685991b16769b9044cc67d558c50e3f5ec38d3f |
Hashes for python_pytun-2.4.1-cp35-cp35m-manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 28523749d0825211af163551a92233455bbd23e128f1d00dd25048b79d97fa34 |
|
MD5 | a51cf24b10898b7a8906d22d9f3414ca |
|
BLAKE2b-256 | e327726e467aab205f546aeb97aa9a36c4ef249fbeb6886d27b95732665b723a |
Hashes for python_pytun-2.4.1-cp35-cp35m-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6575ce39e3bcbb52e98983c0b15da3dcdbbf1866924837e995b3f0b78037ef73 |
|
MD5 | 55ab80eaa68dc37e6dc380749fb53e8f |
|
BLAKE2b-256 | 0a2c052eb74b60ae9bb262ccfa38e22c0fdb3f0598429a11bcf48784ed2b2287 |
Hashes for python_pytun-2.4.1-cp35-cp35m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0b2516d347f5090ba58bd70003d9cb1d6c6071e81bd133f445132d644ed2c631 |
|
MD5 | 266033ad958095ee0e8cedc47a55b051 |
|
BLAKE2b-256 | 79c1e1378cb510a855e902b105b6ad52990f01610d640468fb9446c03da2e5a5 |
Hashes for python_pytun-2.4.1-cp27-cp27mu-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 901aa6206411286b82c1e943fbcc1829192051b208967d5b2a0181a2846c9f98 |
|
MD5 | 31becabbc66dbf9ae29e95e10543432d |
|
BLAKE2b-256 | 3a7a40c7ccca38dd0a7120e333f17b3aa4379a585c22aed93b935b9609fbe26b |
Hashes for python_pytun-2.4.1-cp27-cp27mu-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8c8a2f0c98958ecd038616945c40d00ba6b70ce7da9624ff04cf5ad36b80a85e |
|
MD5 | ef608becaa6908a122b660b3b3946814 |
|
BLAKE2b-256 | 07fae5491ec4195905c28289149898f1ddfe2732f21f275cf05147ff797bf354 |
Hashes for python_pytun-2.4.1-cp27-cp27m-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b1d456e62f32f4d1d7e00d868741d245c58d98602d9b6e99d771b8b5b412572d |
|
MD5 | a66622cad91058a0c20af3647eb4dbae |
|
BLAKE2b-256 | 06143740fba2c5f8200ad51f72e3489c57ec73cce2527f0ab83e3327b191d027 |
Hashes for python_pytun-2.4.1-cp27-cp27m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a971384e2a700b46e2f07adb90d65d60d1c3965e9963964b5f15b0781a6524e1 |
|
MD5 | 31779136456e86e14788cd4c639eaf20 |
|
BLAKE2b-256 | b6936d7b6d4f12ca8fc002fedcf05ab4134f8d36c02fdd329e84b2e6485052f5 |