mirror of
https://github.com/cnotch/ipchub.git
synced 2025-09-26 19:41:18 +08:00
add service
This commit is contained in:
@@ -8,6 +8,7 @@ import (
|
||||
"fmt"
|
||||
"net"
|
||||
"strings"
|
||||
|
||||
"github.com/emitter-io/address"
|
||||
)
|
||||
|
||||
@@ -18,6 +19,21 @@ func GetIP(addr net.Addr) string {
|
||||
return s[:i]
|
||||
}
|
||||
|
||||
// GetLocalIP 获取本地IP
|
||||
func GetLocalIP() []string {
|
||||
addrs, _ := net.InterfaceAddrs()
|
||||
ips := []string{}
|
||||
for _, address := range addrs {
|
||||
// 检查ip地址判断是否回环地址
|
||||
if ipnet, ok := address.(*net.IPNet); ok && !ipnet.IP.IsLoopback() {
|
||||
if ipnet.IP.To4() != nil {
|
||||
ips = append(ips, ipnet.IP.String())
|
||||
}
|
||||
}
|
||||
}
|
||||
return ips
|
||||
}
|
||||
|
||||
// IsLocalhostIP 判断是否为本机IP
|
||||
func IsLocalhostIP(ip net.IP) bool {
|
||||
for _, localhost := range loopbackBlocks {
|
||||
|
Reference in New Issue
Block a user