util-go/net/gateway/gateway_windows.go
2018-08-23 18:29:29 +09:00

19 lines
324 B
Go

package gateway
import (
"net"
"os/exec"
)
func DiscoverGateway() (ip net.IP, iface string, err error) {
output, err := exec.Command("cmd.exe", "/C", "chcp 437 && route print 0.0.0.0").CombinedOutput()
if err != nil {
panic(err)
}
if err != nil {
return nil, "", err
}
return parseWindowsRoutePrint(output)
}