You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
18 lines
261 B
Go
18 lines
261 B
Go
5 years ago
|
package ping
|
||
|
|
||
|
import "net"
|
||
|
|
||
|
// GetIP ...
|
||
|
func GetIP(hostname string) string {
|
||
|
addrs, err := net.LookupIP(hostname)
|
||
|
if err != nil {
|
||
|
return ""
|
||
|
}
|
||
|
for _, addr := range addrs {
|
||
|
if ipv4 := addr.To4(); ipv4 != nil {
|
||
|
return ipv4.String()
|
||
|
}
|
||
|
}
|
||
|
return ""
|
||
|
}
|