Last active
July 6, 2017 07:00
-
-
Save lenew/044bd5b3a6e3edc94b7bb375d7366723 to your computer and use it in GitHub Desktop.
shadowsocks-go http proxy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//a simple go shadowsocks http proxy | |
package main | |
import ( | |
"flag" | |
"fmt" | |
"log" | |
"net" | |
"net/http" | |
"os" | |
eg "github.com/elazarl/goproxy" | |
ss "github.com/shadowsocks/shadowsocks-go/shadowsocks" | |
) | |
var ( | |
listenAddrStr = flag.String("l", "localhost:8080", "listen addr:port") | |
remoteAddrStr = flag.String("r", "", "remote server address and port. 12.12.12.12:8899") | |
encryptionMethodStr = flag.String("m", "aes-256-cfb", "encryption method") | |
encryptionKeyStr = flag.String("k", "", "password") | |
) | |
func main() { | |
flag.Parse() | |
if *remoteAddrStr == "" { | |
fmt.Fprintln(os.Stderr, "parameter remote server required: -r") | |
flag.Usage() | |
os.Exit(1) | |
} | |
if *encryptionKeyStr == "" { | |
fmt.Fprintln(os.Stderr, "parameter password required: -k") | |
os.Exit(1) | |
} | |
p := eg.NewProxyHttpServer() | |
p.Verbose = false | |
cipher, err := ss.NewCipher(*encryptionMethodStr, *encryptionKeyStr) | |
if err != nil { | |
log.Fatal("Failed generating ciphers:", err) | |
} | |
p.Tr.Dial = func(network, addr string) (net.Conn, error) { | |
conn, err := ss.Dial(addr, *remoteAddrStr, cipher.Copy()) | |
if err != nil { | |
log.Fatal("connect to server failed:", err) | |
} | |
return conn, err | |
} | |
log.Fatal(http.ListenAndServe(*listenAddrStr, p)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment