mirror of
https://github.com/ergochat/ergo.git
synced 2024-11-10 22:19:31 +01:00
30 lines
477 B
Go
30 lines
477 B
Go
package irc
|
|
|
|
import (
|
|
"net"
|
|
"strings"
|
|
)
|
|
|
|
func IPString(addr net.Addr) string {
|
|
addrStr := addr.String()
|
|
ipaddr, _, err := net.SplitHostPort(addrStr)
|
|
if err != nil {
|
|
return addrStr
|
|
}
|
|
return ipaddr
|
|
}
|
|
|
|
func AddrLookupHostname(addr net.Addr) string {
|
|
return LookupHostname(IPString(addr))
|
|
}
|
|
|
|
func LookupHostname(addr string) string {
|
|
names, err := net.LookupAddr(addr)
|
|
if err != nil {
|
|
return addr
|
|
}
|
|
|
|
hostname := strings.TrimSuffix(names[0], ".")
|
|
return hostname
|
|
}
|