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.5k Golang : Example of custom handler for Gorilla's Path usage.
+9.1k Golang : Populate or initialize struct with values example
+7.7k Javascript : Push notifications to browser with Push.js
+6.6k Golang : Convert an executable file into []byte example
+6.3k Golang : Get Hokkien(福建话)/Min-nan(閩南語) Pronounciations
+11k Android Studio : Checkbox for user to select options example
+17.3k Golang : When to use init() function?
+10.7k RPM : error: db3 error(-30974) from dbenv->failchk: DB_RUNRECOVERY: Fatal error, run database recovery
+7.4k Golang : How to fix html/template : "somefile" is undefined error?
+23.2k Golang : simulate tail -f or read last line from log file example
+12.2k Golang : Perform sanity checks on filename example
+15.8k Golang : Get checkbox or extract multipart form data value example