Skip to content

Instantly share code, notes, and snippets.

@fangdingjun
fangdingjun / get_original_dst.go
Created January 13, 2017 03:42
golang: get the original destination for the socket when redirect by linux iptables
// get the original destination for the socket when redirect by linux iptables
// refer to https://raw.githubusercontent.com/missdeer/avege/master/src/inbound/redir/redir_iptables.go
//
const (
SO_ORIGINAL_DST = 80
IP6T_SO_ORIGINAL_DST = 80
)
func getOriginalDst(clientConn *net.TCPConn) (rawaddr []byte, host string, newTCPConn *net.TCPConn, err error) {
if clientConn == nil {
@fangdingjun
fangdingjun / stunnel.js
Created May 20, 2015 09:55
The nodejs version of stunnel
var net=require("net");
var tls = require("tls");
/* listen address and port */
var listen_host = "0.0.0.0";
var listen_port = 8080;
/* the upstream https servers */
var servers = [
{host: "a.example.com",port:18080},
@fangdingjun
fangdingjun / generate_address_multiple_chain.go
Last active September 18, 2021 11:15
golang: generate wallet address for multiple chain, base on the same private key, support ethereum, tron network, bitcoin, filecoin
package main
import (
"crypto/rand"
"crypto/sha256"
"encoding/base32"
"encoding/base64"
"encoding/hex"
"encoding/json"
"flag"
@fangdingjun
fangdingjun / socks-server.py
Created December 4, 2015 09:02
a socks server implemented use twisted, support socks4/4a, socks5 protocol, only connect command support
#!python
"""
a socks server implemented by twisted
support socks4/4a, socks5 protocol
only support CONNECT command
#
"""
from twisted.internet.protocol import Protocol
@fangdingjun
fangdingjun / httpdns.go
Created January 15, 2016 04:53
use dnspod's httpdns service to query dns
package main
import (
"bytes"
"fmt"
"github.com/miekg/dns"
"io/ioutil"
"log"
"net/http"
)
@fangdingjun
fangdingjun / chechnet.sh
Created January 25, 2016 01:30
check network connectivity, re-dial when the network is down
#!/bin/bash
# speed check url
url="https://httpbin.org/bytes/10240"
let i=0
timeout=3
while true
do
#ping -c 1 114.114.114.114 >/dev/null 2>&1
@fangdingjun
fangdingjun / golang_build_dll.md
Created March 23, 2017 01:26
build golang package to dll on windows

build golang package to dll on windows, refer to golang/go#11058

go build -buildmode=c-archive -o libxxx.a
gcc -m64 -shared -o xxx.dll xxx.def libxxx.a -Wl,--allow-multiple-definition -static -lstdc++ -lwinmm -lntdll -lWs2_32

lib /def:xxx.def /machine:x64

@fangdingjun
fangdingjun / upgrade_glibc.md
Last active March 16, 2017 03:09
use new version of glibc for your own application

somes times run application on old system, the application requres newer glibc

you can just upgrade glibc for your own application, not system wide

download glibc form GNU website

build it

./configure --prefix=$HOME/myglibc

make

@fangdingjun
fangdingjun / golang_build_android.sh
Created July 29, 2016 04:59
shell script to help to build the golang binary for android, use gomobile
#!/bin/bash
# refer to http://www.sajalkayan.com/post/go-android-binary.html
export GOMOBILE="$GOPATH/pkg/gomobile"
export GOOS=android
export GOARCH=arm
export CC=$GOMOBILE/android-ndk-r12b/arm/bin/arm-linux-androideabi-clang
export CXX=$GOMOBILE/android-ndk-r12b/arm/bin/arm-linux-androideabi-clang++
export CGO_ENABLED=1
export GOARM=7
go build -p=8 -pkgdir=$GOMOBILE/pkg_android_arm -tags="" -ldflags="-extldflags=-pie" "$@"
@fangdingjun
fangdingjun / python27.py
Last active October 28, 2016 08:02
build a seperate python gtk develop environment for windows, this is a open to use environment, no need to install python. run `setup.py build` and copy the build directory to an other windows, you can use python27_console.exe to run the script.
#!python
# -*- coding: utf-8 -*-
import code
import os
import sys
if __name__ == "__main__":
libraries = ["python27.zip", "library.zip"]
for f in libraries: