Skip to content

Instantly share code, notes, and snippets.

@glacjay
glacjay / tun-ping-mac.py
Created September 19, 2010 15:59
Reading/writing Mac's TUN/TAP device using Python.
import os
import subprocess
# Open file corresponding to the TUN device.
tun = open('/dev/tun0', 'r+b')
# Bring it up and assign addresses.
subprocess.check_call('ifconfig tun0 192.168.7.1 192.168.7.2 up', shell=True)
@glacjay
glacjay / tun-ping-linux.go
Created September 18, 2010 12:26
Reading/Writing Linux's TUN/TAP device in Go.
package main
import (
"exec"
"log"
"os"
"syscall"
"unsafe"
)
@glacjay
glacjay / tun-ping-linux.py
Created September 18, 2010 04:49
Reading/writing Linux's TUN/TAP device using Python.
import fcntl
import os
import struct
import subprocess
# Some constants used to ioctl the device file. I got them by a simple C
# program.
TUNSETIFF = 0x400454ca
TUNSETOWNER = TUNSETIFF + 2