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
+7.4k Ubuntu : connect() to unix:/var/run/php5-fpm.sock failed (13: Permission denied) while connecting to upstream
+12.7k Linux : How to install driver for 600Mbps Dual Band Wifi USB Adapter
+10.9k Golang : Underscore string example
+7.8k Golang : Convert(cast) io.Reader type to string
+28k PHP : Convert(cast) string to bigInt
+8k Golang : Getting Echo framework StartAutoTLS to work
+24.2k Golang : Fix type interface{} has no field or no methods and type assertions example
+5.2k Linux : How to set root password in Linux Mint
+52.9k Golang : How to get struct field and value by name
+20.4k Golang : Convert seconds to human readable time format example
+23.3k Golang : simulate tail -f or read last line from log file example
+7.1k Fix sudo yum hang problem with no output or error messages