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
+16.4k CodeIgniter/PHP : Create directory if does not exist example
+8.8k Golang : HTTP Routing with Goji example
+11.9k Golang : Determine if time variables have same calendar day
+5.6k PHP : Convert CSV to JSON with YQL example
+6.9k Mac/Linux/Windows : Get CPU information from command line
+17.8k Golang : Iterate linked list example
+23.5k Golang : Get ASCII code from a key press(cross-platform) example
+5.2k Golang : PGX CopyFrom to insert rows into Postgres database
+10.1k Golang : Test a slice of integers for odd and even numbers
+29.1k Golang : Get first few and last few characters from string
+6.1k Golang : Missing Subversion command
+15.4k Golang : invalid character ',' looking for beginning of value