Golang : Validate IPv6 example
This tutorial is an enhancement of previous tutorial on how to determine if a given IP address is version 4 or 6. The govalidator package has a function to validate if a given IP address is of type version 6 or not.
Here you go!
package main
import (
"fmt"
"github.com/asaskevich/govalidator"
)
func main() {
IP61 := "2001:0db8:0000:0042:0000:8a2e:0370:7334"
validIP61 := govalidator.IsIPv6(IP61)
fmt.Printf("%s is a valid IPv6 address : %v \n", IP61, validIP61)
IP62 := "FE80::0202:B3FF:FE1E:8329"
validIP62 := govalidator.IsIPv6(IP62)
fmt.Printf("%s is a valid IPv6 address : %v \n", IP62, validIP62)
}
Output :
2001:0db8:0000:0042:0000:8a2e:0370:7334 is a valid IPv6 address : true
FE80::0202:B3FF:FE1E:8329 is a valid IPv6 address : true
References :
https://www.socketloop.com/tutorials/golang-check-if-ip-address-is-version-4-or-6
See also : Golang : Validate IP address
By Adam Ng
IF you gain some knowledge or the information here solved your programming problem. Please consider donating to the less fortunate or some charities that you like. Apart from donation, planting trees, volunteering or reducing your carbon footprint will be great too.
Advertisement
Tutorials
+5k Golang : Function as an argument type example
+6.6k Gogland : Single File versus Go Application Run Configurations
+9.8k Golang : How to determine a prime number?
+15k Golang : How to extract links from web page ?
+81.3k Golang : How to convert character to ASCII and back
+17.3k Golang : Example for RSA package functions
+8.9k Golang : Simple Jawi(Yawi) to Rumi(Latin/Romanize) converter
+11k Golang : Get month name from date example
+14.2k Golang : Get current time from the Internet time server(ntp) example
+4k Golang : Print instead of building pyramids
+8.3k Golang : ffmpeg with os/exec.Command() returns non-zero status
+14.3k Golang : How to convert(cast) IP address to string?