FindPrimaryAddr returns the primary outbound IP of this machine. This is the same as find_primary_addr in sgcollect_info.
()
| 1101 | // FindPrimaryAddr returns the primary outbound IP of this machine. |
| 1102 | // This is the same as find_primary_addr in sgcollect_info. |
| 1103 | func FindPrimaryAddr() (net.IP, error) { |
| 1104 | conn, err := net.Dial("udp", "8.8.8.8:56") |
| 1105 | if err != nil { |
| 1106 | return nil, err |
| 1107 | } |
| 1108 | |
| 1109 | localAddr := conn.LocalAddr().(*net.UDPAddr) |
| 1110 | return localAddr.IP, conn.Close() |
| 1111 | } |
| 1112 | |
| 1113 | // ReplaceAll returns a string with all of the given chars replaced by new |
| 1114 | func ReplaceAll(s, chars, new string) string { |