Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
check whether an ip is loopback
package main
import "fmt"
import "net"
func main() {
IPv4Loopback := net.ParseIP("127.0.0.1")
IPv6Loopback := net.ParseIP("::1")
NonIPv6LoopbackOne := net.ParseIP("2001:db8::1")
NonIPv6LoopbackTwo := net.ParseIP("fe80::1%lo0")
fmt.Println(IPv4Loopback.IsLoopback())
fmt.Println(IPv6Loopback.IsLoopback())
fmt.Println(NonIPv6LoopbackOne.IsLoopback())
fmt.Println(NonIPv6LoopbackTwo.IsLoopback())
}
@andyxning

This comment has been minimized.

Copy link
Owner Author

commented Dec 9, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.