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
+28.1k Golang : Change a file last modified date and time
+9.4k Golang : Detect number of active displays and the display's resolution
+13.8k Golang : Google Drive API upload and rename example
+19.8k Golang : Compare floating-point numbers
+9.9k Golang : Print how to use flag for your application example
+7.2k Golang : Check to see if *File is a file or directory
+8.1k Your page has meta tags in the body instead of the head
+8k Swift : Convert (cast) Character to Integer?
+42.6k Golang : Convert []byte to image
+4.9k Golang : Customize scanner.Scanner to treat dash as part of identifier
+17.2k Golang : Clone with pointer and modify value
+12.4k Golang : Sort and reverse sort a slice of bytes