util-go/net/gateway/gateway_windows.go
2018-08-23 16:32:40 +09:00

21 lines
360 B
Go

package gateway
import (
"log"
"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)
}
log.Println(string(output))
if err != nil {
return nil, "", err
}
return parseWindowsRoutePrint(output)
}