diff --git a/tunmgr/requirements.txt b/tunmgr/requirements.txt new file mode 100644 index 0000000000000000000000000000000000000000..4ca7268ae906737c32e7bad30a244bc98985ce32 --- /dev/null +++ b/tunmgr/requirements.txt @@ -0,0 +1,2 @@ +python-pytun==2.2.1 +wheel==0.24.0 diff --git a/tunmgr/tunmgr.py b/tunmgr/tunmgr.py new file mode 100755 index 0000000000000000000000000000000000000000..dcd1ec749bffb7d9f4377a8175f0a9e38e5e1d4e --- /dev/null +++ b/tunmgr/tunmgr.py @@ -0,0 +1,38 @@ +#!/usr/bin/python3 + +from pytun import TunTapDevice +import selectors +import socket + + +tun = TunTapDevice() + + +tun.addr = '10.8.0.1' +tun.dstaddr = '10.8.0.2' +tun.netmask = '255.255.255.0' +tun.mtu = 400 + +tun.up() + +PEER = "10.4.25.25" +PORT = 1456 +s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) +s.bind(('', PORT)) + + +sel = selectors.DefaultSelector() + +sel.register(tun, selectors.EVENT_READ, "tun") +sel.register(s, selectors.EVENT_READ, "sms") + +while 1: + for key, events in sel.select(): + if key.data=="tun": + s.sendto(tun.read(tun.mtu), (PEER, PORT)) + elif key.data == "sms": + tun.write(s.read(tun.mtu)) + + + +