Advertisement
Guest User

Untitled

a guest
Sep 26th, 2017
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.50 KB | None | 0 0
  1. import socket
  2. import select
  3.  
  4. MTU = 1168
  5. IPS = "ip1", "ip2"
  6. TARGET = "targetip", 4444
  7.  
  8. tunnel = open("/dev/tun0", "rw")
  9.  
  10. sockets = [socket.socket(socket.AF_INET, sock.SOCK_DGRAM) for x in IPS]
  11. for ip, s in zip(ips, sockets):
  12. s.bind((ip, 1))
  13.  
  14. rr = []
  15. while True:
  16. r, w, _ = select.select([tunnel] + sockets, [], [])
  17. for fd in w:
  18. if fd == tunnel:
  19. if not rr:
  20. rr = list(sockets)
  21. rr.pop(0).sendto(TARGET, tunnel.read(MTU))
  22. else:
  23. tunnel.write(fd.recv(MTU))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement