Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can I set a proxy login when I log in? #1451

Open
NoSugarTing opened this issue Oct 11, 2024 · 2 comments
Open

Can I set a proxy login when I log in? #1451

NoSugarTing opened this issue Oct 11, 2024 · 2 comments

Comments

@NoSugarTing
Copy link

Can I set a proxy login when I log in? I don't see any way to configure it, please help me, thank you very much !!!

@Flipped199
Copy link

yes

sock5, _ := proxy.SOCKS5("tcp", "10.0.0.14:7890", &proxy.Auth{
    User:     "",
    Password: "",
}, proxy.Direct)
dc := sock5.(proxy.ContextDialer)

client := telegram.NewClient(appID, appHash, telegram.Options{
    Resolver:       dcs.Plain(dcs.PlainOptions{Dial: dc.DialContext}), 
})

@prdsrm
Copy link

prdsrm commented Oct 15, 2024

Yes, it is possible just like @Flipped199 said it.
You can also abstract a little bit and use proxy.FromURL so, you will be able to mix between SOCKS5 & HTTP/HTTP(s) proxies, like this:

func NewDialer(proxyConnStr string) (proxy.Dialer, error) {
	url, err := url.Parse(proxyConnStr)
	if err != nil {
		return nil, err
	}
	socks5, err := proxy.FromURL(url, proxy.Direct)
	if err != nil {
		return nil, err
	}
	return socks5, nil
}

func NewResolver(proxyConnStr string) (dcs.Resolver, error) {
	var resolver dcs.Resolver
	socks5, err := NewDialer(proxyConnStr)
	if err != nil {
		return nil, err
	}
	dc := socks5.(proxy.ContextDialer)
	resolver = dcs.Plain(dcs.PlainOptions{
		Dial: dc.DialContext,
	})
	return resolver, nil
}

proxy := "https://proxy_userid:proxy_password@proxy_ip:proxy_port"
resolver, err = NewResolver(proxy)
if err != nil {
    return err
}
client := telegram.NewClient(appID, appHash, telegram.Options{
    Resolver:       dcs.Plain(dcs.PlainOptions{Dial: dc.DialContext}), 
})

You need to use the package"golang.org/x/net/proxy" and import "github.com/gotd/td/telegram/dcs" as well.

This question should be asked in the "discussions" section to be honest, and it was already answered here: #714.
same here: #790.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants