go-ircevent icon indicating copy to clipboard operation
go-ircevent copied to clipboard

Make connection using specific ip

Open kofany opened this issue 3 years ago • 7 comments

Can we bind specifc ip to irc connection?

kofany avatar Oct 05 '22 06:10 kofany

Not in the current code. After this line: https://github.com/thoj/go-ircevent/blob/73e444401d645f686b4aa9adcab88fa78cf85a4f/irc.go#L465 Add dialer.LocalAddress := "192.168.0.2"

Pr Welcome.

thoj avatar Oct 05 '22 07:10 thoj

Hi again, im getting an error: dialer.LocalAddress undefined (type proxy.Dialer has no field or method LocalAddress)

kofany avatar Oct 05 '22 10:10 kofany

the code is:

    dialer := proxy.FromEnvironmentUsing(&net.Dialer{Timeout: irc.Timeout})
dialer.LocalAddress = "127.0.0.1"
irc.socket, err = dialer.Dial("tcp", irc.Server)

kofany avatar Oct 05 '22 10:10 kofany

dialer := proxy.FromEnvironmentUsing(&net.Dialer{Timeout: irc.Timeout, LocalAddress: "127.0.0.1"})
irc.socket, err = dialer.Dial("tcp", irc.Server)

thoj avatar Oct 05 '22 10:10 thoj

Sorry but also error irc.go:466:73: unknown field 'LocalAddress' in struct literal of type net.Dialer

kofany avatar Oct 05 '22 10:10 kofany

try LocalAddr

If that doesn't work I don't know. Check the go documentation.

thoj avatar Oct 05 '22 10:10 thoj

Hi i manage to get it work with code: (all changes You can see on my GitHub (In fork)

dialer := proxy.FromEnvironmentUsing(&net.Dialer{ LocalAddr: &net.TCPAddr{
        IP:   net.ParseIP(irc.myhost),
        Port: 0,
    	},Timeout: irc.Timeout})
	
//where myhost is passed here:
func IRC(nick, user string, myhost string) *Connection {
	// catch invalid values

kofany avatar Nov 03 '22 07:11 kofany