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
+6.7k Golang : Muxing with Martini example
+7.8k Golang : Ways to recover memory during run time.
+5.3k Swift : Convert string array to array example
+4.6k Mac OSX : Get disk partitions' size, type and name
+14.6k Golang : Get URI segments by number and assign as variable example
+8.9k Golang : Get SPF and DMARC from email headers to fight spam
+11.2k Golang : Post data with url.Values{}
+7k Golang : Squaring elements in array
+11.5k Golang : Surveillance with web camera and OpenCV
+13.3k Golang : error parsing regexp: invalid or unsupported Perl syntax
+17.4k Golang : Find smallest number in array
+23.3k Golang : Get ASCII code from a key press(cross-platform) example