package main import ( "fmt" "net" ) func main() { ip := net.ParseIP("127.0.0.1") if ip.IsLoopback() { fmt.Println("IP is loopback") } else { fmt.Println("IP is not loopback") } }
package main import ( "fmt" "net" ) func main() { addrs, err := net.InterfaceAddrs() if err != nil { fmt.Println(err) return } for _, addr := range addrs { ipnet, ok := addr.(*net.IPNet) if ok && !ipnet.IP.IsLoopback() { fmt.Println(ipnet.IP) } } }In this example, we use the "InterfaceAddrs" method to get a list of network interface addresses. Then, we loop through each address and use the "IsLoopback" method to check if it is a loopback address. If it's not a loopback address, we print the IP address. The "net" package library is used in these examples to work with IP addresses and network interfaces.