OS: macOS
Routing table:
# netstat -nr
Routing tables
Internet:
Destination Gateway Flags Netif Expire
default 192.168.0.1 UGSc en0
1.1.1.1/32 127.0.0.1 UGSc lo0
127 127.0.0.1 UCS lo0
127.0.0.1 127.0.0.1 UH lo0
169.254 link#6 UCS en0 !
192.168.0 link#6 UCS en0 !
192.168.0.1/32 link#6 UCS en0 !
192.168.0.1 66:c4:b4:70:cc:7d UHLWIir en0 1181
192.168.0.23 b6:91:26:63:85:d6 UHLWIi en0 902
192.168.0.193/32 link#6 UCS en0 !
224.0.0/4 link#6 UmCS en0 !
224.0.0.251 1:0:5e:0:0:fb UHmLWI en0
230.230.230.230 1:0:5e:66:e6:e6 UHmLWI en0
239.255.255.250 1:0:5e:7f:ff:fa UHmLWI en0
255.255.255.255/32 link#6 UCS en0 !
As you see, the destination 1.1.1.1/32
is routed to gateway 127.0.0.1
. How do I dial to 1.1.1.1
via gateway 192.168.0.1
in Go without deleting the route?
The following example code is not working:
from := &net.TCPAddr{
IP: net.ParseIP("192.168.0.193"),
Port: 0,
}
to := &net.TCPAddr{
IP: net.ParseIP("1.1.1.1"),
Port: 443,
}
c, err := net.DialTCP("tcp", from, to)
if err != nil {
panic(err)
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…