Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you read/write TUN/TAP interfaces with python3?

Tags:

python-3.x

There is code that works great for python 2 here: https://gist.github.com/glacjay/585369, but running that same code on python3 (3.4 and 3.5 tested) the open call fails with:

tun = open('/dev/net/tun', 'r+b')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
io.UnsupportedOperation: File or stream is not seekable.

I found suggestions to add buffering=0 to the open call. The open call succeeded when I did that, but when I tried to read the tap device I got nothing.

like image 819
krupan Avatar asked Mar 02 '26 01:03

krupan


1 Answers

I'm using a similar code to implement TUN/TAP interfaces support in Scapy, and for what it's worth, using buffering=0 worked fine in this case.

like image 143
Pierre Avatar answered Mar 03 '26 18:03

Pierre



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!