Skip to content

Instantly share code, notes, and snippets.

View imthaghost's full-sized avatar
🐿️
Spawning gophers

Gary Frederick imthaghost

🐿️
Spawning gophers
View GitHub Profile
@imthaghost
imthaghost / main.go
Last active March 6, 2022 07:16
MerryGoRound main
func main() {
// configuration for tor client
tor := ht.Tor {
MaxTimeout: 20 * time.Second,
MaxIdleConnections: 10,
}
// new instance of tor client
torClient := tor.New()
@imthaghost
imthaghost / tor.go
Created September 19, 2021 23:03
Represents an HTTP Client over the Tor network
// Tor represents an HTTP Client over the Tor network
type Tor struct {
MaxTimeout time.Duration // Max Timeout
MaxIdleConnections int // Max Idle Connections
Transport *http.Transport // Custom Transport
once sync.Once // sync so we only set up 1 client
netClient *http.Client // http client
}
// New creates an instance of a Tor Client
@imthaghost
imthaghost / smartproxy.go
Last active September 20, 2021 07:41
SmartProxy initializes and returns a proxy function for use in a Transport
// SmartProxy initializes and returns a proxy function for use in a Transport
func SmartProxy() func(*http.Request) (*url.URL, error) {
// base url
base := "https://%s:%s@%s"
// fill credentials into url
rawUrl := fmt.Sprintf(base, <YOUR_SMARTPROXY_USERNAME>, <YOUR_SMARTPROXY_PASSWORD>, "gate.dc.smartproxy.com:20000")
// parse proxy url
proxyUrl, err := url.Parse(rawUrl)
@imthaghost
imthaghost / tor.go
Last active September 20, 2021 07:39
Tor proxy
// 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"