Tun/Tap Driver using OpenVPN and DeviceIoControl

Andrew nobody at yahoo.com
Thu May 22 19:57:07 EDT 2008


Hello I am trying to port some code and I am running into some issues I 
may or may not be able to solve on my own and would appreciate your help

Basically I am trying to open the Tun Driver through openvpn in Ether 
(Tap mode).

code is as follows

f = win32file.CreateFile("C:\\WINDOWS\\System32\\drivers\\tunmp.sys", 
GENERIC_READ, 0, None, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0)
if WINDOWS:
         ifs = win32file.DeviceIoControl(f, TUNSETIFF, 
struct.pack("16sH", "wj%d", TUNMODE), 0, None)
else:
         ifs = ioctl(f, TUNSETIFF, struct.pack("16sH", "wj%d", TUNMODE))
ifname = ifs[:16].strip("\x00")
print "Interface %s created. Configure it and use it" % ifname

but does not seem to work so well I get "The Paramater is incorrect"

Traceback (most recent call last):
   File "wifi.py", line 167, in <module>
     ifs = win32file.DeviceIoControl(f, TUNSETIFF, struct.pack("16sH", 
"wj%d", TU
NMODE), 0, None)
pywintypes.error: (87, 'DeviceIoControl', 'The parameter is incorrect.')


Would appreciate any help

Ty



More information about the Python-list mailing list