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
263 B
Go
18 lines
263 B
Go
2 years ago
|
package tcping
|
||
|
|
||
|
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 ""
|
||
|
}
|