The tun-ping-responder.py file is a standalone Python script which contains all the code you need to use tun
on Windows.
The file should be self-explanatory. Here are some keys and gotchas for understanding it:
ReadThread
listens for IPv4 and IPv6 packets sent by the kernel; if these are echo requests, it formats an echo reply and sends that back.WriteThread
periodically sends IPv4 and IPv6 echo requests, and prints when it receives the corresponding replies.tun
interface is a Windows file which is accessed through the ReadFile()
and WriteFile()
functions. It does so in OVERLAPPED
mode, so that a call to ReadFile()
does not block the call of WriteFile()
.Start the script. You will see that the script (in fact the WriteThread
thread) sends period echo requests.
componentId = {A9A413D7-4D1C-47BA-A3A9-92F091828881} tuntap = 208 Press enter to stop... Transmitting IPv6 echo request Received IPv6 echo reply Transmitting IPv4 echo request Received IPv4 echo reply Transmitting IPv6 echo request Received IPv6 echo reply Transmitting IPv4 echo request Received IPv4 echo reply Transmitting IPv6 echo request Received IPv6 echo reply |
Start Wireshark on your tun
interface to see the packets:
Open a command prompt and ping any IP address in the 10.2.0.xx
and bbbb:/64
address ranges. The script will answer those.
Microsoft Windows [Version 6.0.6002] Copyright (c) 2006 Microsoft Corporation. All rights reserved. C:\Users\Thomas>ping 10.2.0.55 Pinging 10.2.0.55 with 32 bytes of data: Reply from 10.2.0.55: bytes=32 time=1ms TTL=128 Reply from 10.2.0.55: bytes=32 time=1ms TTL=128 Reply from 10.2.0.55: bytes=32 time=1ms TTL=128 Reply from 10.2.0.55: bytes=32 time=1ms TTL=128 Ping statistics for 10.2.0.55: Packets: Sent = 4, Received = 4, Lost = 0 (0% loss), Approximate round trip times in milli-seconds: Minimum = 1ms, Maximum = 1ms, Average = 1ms C:\Users\Thomas>ping bbbb::21 Pinging bbbb::21 from bbbb::1 with 32 bytes of data: Reply from bbbb::21: time=1ms Reply from bbbb::21: time=1ms Reply from bbbb::21: time=1ms Reply from bbbb::21: time=1ms Ping statistics for bbbb::21: Packets: Sent = 4, Received = 4, Lost = 0 (0% loss), Approximate round trip times in milli-seconds: Minimum = 1ms, Maximum = 1ms, Average = 1ms |