Skip to content

Instantly share code, notes, and snippets.

@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
@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-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-mac.go
Created September 19, 2010 16:03
Reading/Writing Mac's TUN/TAP device using Go.
package main
import (
"exec"
"log"
"os"
)
func main() {
file, err := os.Open("/dev/tun0", os.O_RDWR, 0)
@glacjay
glacjay / tun-ping-win.py
Created September 19, 2010 16:24
Reading/Writing OpenVPN's TUN/TAP Device under Windows using Python.
import _winreg as reg
import win32file
adapter_key = r'SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002BE10318}'
def get_device_guid():
with reg.OpenKey(reg.HKEY_LOCAL_MACHINE, adapter_key) as adapters:
try:
@glacjay
glacjay / gist:856140
Created March 5, 2011 05:13
Show a problem about CR/LF under Linux.
# Save this file using DOS's CR/LF.
export VAR1=blahblahblah
export VAR2=hello
export VAR1=$VAR1:$VAR2
@glacjay
glacjay / gist:856270
Created March 5, 2011 09:59
A simple tool to find out a particular machine's IP address within a LAN.
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <pthread.h>
#include <unistd.h>
#include <arpa/inet.h>
@glacjay
glacjay / sudoku.go
Created July 9, 2011 10:35
Solve Sudoku problems in Go.
package main
import (
"io/ioutil"
"log"
"os"
"regexp"
"strings"
)
@glacjay
glacjay / IframeDemo.vue
Last active January 7, 2018 09:20
vue 集成 iframe
<template>
<iframe :src="the_url" @load="onIframeLoad" />
</template>
<script>
export default {
data () {
return {
the_url: "http://xxx.com/yyy",
some_id: 42
@glacjay
glacjay / wubi86_single.py
Created January 27, 2021 08:50
制作 rime 五笔86 单字词库
# forked from https://github.com/yekingyan/rime-wubi-86-single/blob/master/wubi86_single.py
import re
INPUT_FILE_PATH = "wubi86.dict.yaml"
OUTPUT_FILE_PATH = "wubi86.dict.yaml.single"