Created
May 25, 2018 06:48
-
-
Save Evilcry/1f300876be3a093c5188ef023b855b0a to your computer and use it in GitHub Desktop.
Simpe Golang TOR base implementation
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
// Ref. https://gist.github.com/mmcloughlin/17e3ca302785f0e525655191d3f9211d | |
package main | |
import ( | |
"fmt" | |
"io/ioutil" | |
"log" | |
"net/http" | |
"golang.org/x/net/proxy" | |
) | |
func main() { | |
// Create a socks5 dialer | |
dialer, err := proxy.SOCKS5("tcp", "127.0.0.1:9050", nil, proxy.Direct) | |
if err != nil { | |
log.Fatal(err) | |
} | |
// Setup HTTP transport | |
tr := &http.Transport{ | |
Dial: dialer.Dial, | |
} | |
client := &http.Client{Transport: tr} | |
res, err := client.Get("https://httpbin.org/ip") | |
if err != nil { | |
log.Fatal(err) | |
} | |
d, err := ioutil.ReadAll(res.Body) | |
if err != nil { | |
log.Fatal(err) | |
} | |
fmt.Println(string(d)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment