Golang net.IP.Equal() function example
package net
Golang net.IP.Equal() function usage example
package main
import (
"fmt"
"net"
)
func main() {
// google.com ip version 4 and 6 addresses
// from https://www.socketloop.com/tutorials/golang-resolve-domain-name-ip4-ip6
ip4 := "74.125.130.105"
ip4two := "74.125.130.105"
ip6 := "2404:6800:4003:c01::6a"
// conver to IP type
ipAdd4 := net.ParseIP(ip4)
ipAdd4two := net.ParseIP(ip4two)
ipAdd6 := net.ParseIP(ip6)
same := ipAdd4.Equal(ipAdd4two)
fmt.Println("The ip4 same as ip4two address : ", same)
same = ipAdd4.Equal(ipAdd6)
fmt.Println("The ip4 same as ip6 address : ", same)
}
Output :
The ip4 same as ip4two address : true
The ip4 same as ip6 address : false
References :
http://golang.org/pkg/net/#IP.Equal
https://www.socketloop.com/tutorials/golang-resolve-domain-name-ip4-ip6
Advertisement
Something interesting
Tutorials
+6.9k Golang : Decode XML data from RSS feed
+25k Golang : Create PDF file from HTML file
+7.5k SSL : How to check if current certificate is sha1 or sha2 from command line
+8.7k Golang : Find duplicate files with filepath.Walk
+3.7k Golang : Switch Redis database redis.NewClient
+14k Golang : Fix cannot use buffer (type bytes.Buffer) as type io.Writer(Write method has pointer receiver) error
+4.7k PHP : Extract part of a string starting from the middle
+10.3k Golang : Embed secret text string into binary(executable) file
+15.6k Golang : How to convert(cast) IP address to string?
+6.8k Get Facebook friends working in same company
+5.8k Javascript : How to replace HTML inside <div>?