如何在Golang中添加socks5 auth到一个net.conn?

wlzqhblo  于 2022-12-07  发布在  Go
关注(0)|答案(2)|浏览(142)

如何创建一个net.Conn连接到一个带有用户/密码身份验证的Socks 5服务器

conn,err:=net.Dial("tcp","user:pass@ip_addr:port")
5uzkadbs

5uzkadbs1#

d, err := proxy.SOCKS5("tcp", surl.Host, auth, forwrder)
    if err != nil {
        return nil, err
    }

    conn, err := d.Dial("tcp", testURL)
    if err != nil {
        return nil, err
    }
    defer conn.Close()
u3r8eeie

u3r8eeie2#

import (
        "net"   
        "time"
        "golang.org/x/net/proxy"
    )

    auth := proxy.Auth{User: "username", Password: "password"}
    dailer, err := proxy.SOCKS5("tcp", "socks5_ip:port", &auth, &net.Dialer{
        Timeout:   60 * time.Second,
        KeepAlive: 30 * time.Second,
    })
    conn, err := dailer.Dial("tcp", "target_ip:port")

相关问题