Skip to content

Instantly share code, notes, and snippets.

@mmcloughlin
Last active March 15, 2021 15:44
Show Gist options
  • Save mmcloughlin/17e3ca302785f0e525655191d3f9211d to your computer and use it in GitHub Desktop.
Save mmcloughlin/17e3ca302785f0e525655191d3f9211d to your computer and use it in GitHub Desktop.
Tor from Golang
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))
}
@chinyavadav
Copy link

hie how can i reset the public ip manually in the code

@raifpy
Copy link

raifpy commented Jul 23, 2020

os.Setenv("HTTP_PROXY","socks5://127.0.0.1:9050")

i think this is more easier

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment