Skip to content

Instantly share code, notes, and snippets.

@andyxning
Created December 9, 2015 08:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andyxning/fd42cbb09016977c0daa to your computer and use it in GitHub Desktop.
Save andyxning/fd42cbb09016977c0daa to your computer and use it in GitHub Desktop.
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
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment