Created
December 9, 2015 08:48
-
-
Save andyxning/fd42cbb09016977c0daa to your computer and use it in GitHub Desktop.
check whether an ip is loopback
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
http://play.golang.org/p/RwzIsmYZwt