util/net/gateway/gateway_darwin.go

17 lines
276 B
Go
Raw Permalink Normal View History

2017-09-11 18:59:00 +09:00
package gateway
import (
"net"
"os/exec"
)
2017-12-02 00:43:09 +09:00
func DiscoverGateway() (ip net.IP, iface string, err error) {
2017-09-11 18:59:00 +09:00
routeCmd := exec.Command("netstat", "-rn")
output, err := routeCmd.CombinedOutput()
if err != nil {
2017-12-02 00:43:09 +09:00
return nil, "", err
2017-09-11 18:59:00 +09:00
}
return parseDarwinRouteGet(output)
}