Last active
March 15, 2021 15:44
-
-
Save mmcloughlin/17e3ca302785f0e525655191d3f9211d to your computer and use it in GitHub Desktop.
Tor from Golang
This file contains hidden or 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
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)) | |
} |
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
hie how can i reset the public ip manually in the code