Skip to content

Instantly share code, notes, and snippets.

View jannson's full-sized avatar
💭
I may be slow to respond.

Jason jannson

💭
I may be slow to respond.
View GitHub Profile
@jannson
jannson / bloom.go
Created April 1, 2016 06:59
simplest bloom implement for golang
// Copyright 2011 [email protected]. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package main
/*
A Bloomfilter is a negative filter which quickly
determines whether a word is present in a large set
of words, given that all words have been added to the
@jannson
jannson / etc.json
Last active February 22, 2016 11:12
rss-scripts
{
"server":"0.0.0.0",
"server_ipv6": "[::]",
"local_address":"127.0.0.1",
"local_port":1080,
"port_password":{
"14241":"j",
"14141":"k",
"15321":"o"
},
@jannson
jannson / Naive-VPN.md
Created February 17, 2016 08:29 — forked from klzgrad/Naive-VPN.md
朴素VPN:一个纯内核级静态隧道

朴素VPN:一个纯内核级静态隧道

由于路由管控系统的建立,实时动态黑洞路由已成为最有效的封锁手段,TCP连接重置和DNS污染成为次要手段,利用漏洞的穿墙方法已不再具有普遍意义。对此应对方法是多样化协议的VPN来抵抗识别。这里介绍一种太简单、有时很朴素的“穷人VPN”。

朴素VPN只需要一次内核配置(Linux内核),即可永久稳定运行,不需要任何用户态守护进程。所有流量转换和加密全部由内核完成,原生性能,开销几乎没有。静态配置,避免动态握手和参数协商产生指纹特征导致被识别。并且支持NAT,移动的内网用户可以使用此方法。支持广泛,基于L2TPv3标准,Linux内核3.2+都有支持,其他操作系统原则上也能支持。但有两个局限:需要root权限;一个隧道只支持一个用户。

朴素VPN利用UDP封装的静态L2TP隧道实现VPN,内核XFRM实现静态IPsec。实际上IP-in-IP隧道即可实现VPN,但是这种协议无法穿越NAT,因此必须利用UDP封装。内核3.18将支持Foo-over-UDP,在UDP里面直接封装IP,与静态的L2TP-over-UDP很类似。

创建一个朴素VPN

@jannson
jannson / echo.go
Last active January 13, 2016 04:09 — forked from paulsmith/echo.go
A simple echo server testing a few interesting Go language features, goroutines and channels.
// $ 6g echo.go && 6l -o echo echo.6
// $ ./echo
//
// ~ in another terminal ~
//
// $ nc localhost 3540
package main
import (
# Firewall configuration written by system-config-firewall
# Manual customization of this file is not recommended.
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
@jannson
jannson / py_db.py
Last active November 29, 2015 06:21
def insert_sample(table, sample):
place_holder = ",".join(["{%d} " % idx for idx, _ in enumerate(sample.values())])
columns = ", ".join(sample.keys())
sql = "insert into `%s` (%s) values(%s)" % (table, columns, place_holder)
exec_sql = sql.format(*sample.values())
print exec_sql
cursor.execute(exec_sql)
insert_sample('firmware', {"aaa":"bbb","ccc":"ddd"})
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import ipaddress
import codecs
import sys
#install:
#pip install ipaddress
#
# CMake Toolchain file for crosscompiling on ARM.
#
# This can be used when running cmake in the following way:
# cd build/
# cmake .. -DCMAKE_TOOLCHAIN_FILE=../cross-arm-linux-gnueabihf.cmake
#
set(CROSS_PATH /projects/asuswrt-merlin2/release/src-rt-6.x.4708/toolchains/hndtools-arm-linux-2.6.36-uclibc-4.5.3)
@jannson
jannson / udp-client.go
Last active August 29, 2015 14:22
udp echo test
package main
import (
"bufio"
"errors"
"fmt"
"math/rand"
"net"
"os"
"time"
from PIL import Image
from PIL.ExifTags import TAGS, GPSTAGS
def get_exif_data(image):
"""Returns a dictionary from the exif data of an PIL Image item. Also converts the GPS Tags"""
exif_data = {}
info = image._getexif()
if info:
for tag, value in info.items():
decoded = TAGS.get(tag, tag)