Last active
September 20, 2021 07:39
-
-
Save imthaghost/5caaa8ed98c4ec11e81aeaccb42b574c to your computer and use it in GitHub Desktop.
Tor 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
// TorProxy initializes and returns a TOR SOCKS proxy function for use in a Transport | |
func TorProxy() func(*http.Request) (*url.URL, error) { | |
// A source of uniformly-distributed pseudo-random | |
rand.Seed(time.Now().UnixNano()) | |
// Pseudo-random int value | |
num := rand.Intn(0x7fffffff-10000) + 10000 | |
// Tor listens for SOCKS connections on localhost port 9050 | |
base := "socks5://%d:x@127.0.0.1:9050" | |
// proxy url with random credentials | |
rawUrl := fmt.Sprintf(base, num) | |
// Parse proxy url | |
proxyUrl, err := url.Parse(rawUrl) | |
if err != nil { | |
fmt.Println("invalid url to parse when creating proxy transport. err: ", err) | |
return nil | |
} | |
// Setup proxy transport | |
proxy := http.ProxyURL(proxyUrl) | |
return proxy | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment