JS Verification:
IPv4 address verification:
Function querydev (IP) {var exp =/^ (\ D {1, 2} | 1 \ D \ d | 2 [0-4] \ d | 25 [0-5]) \. (\ D {1, 2} | 1 \ D \ d | 2 [0-4] \ d | 25 [0-5]) \. (\ D {1, 2} | 1 \ D \ d | 2 [0-4] \ d | 25 [0-5]) \. (\ D {1, 2} | 1 \ D \ d | 2 [0-4] \ d | 25 [0-5]) $/; var flag = IP. match (exp); If (flag! = Undefined & flag! = "") {Return true;} else {return false ;}< input type = "text" name = "iporname" id = "iporname" style = "width: 80px; "value =" "/> <input name =" Submit "type =" button "value =" verify IPv4 "onclick = alert (querydev (iporname. value) style = "width: 80px"/> verify the IPv6 address:
Function querydev (ipvalue) {var isipv6 = false; If (ipvalue. Match (/:/g). Length <= 7 &/:/. Test (ipvalue )? /^ ([\ Da-F] {} (:|::) {} [\ da-F] {} $/I. test (ipvalue):/^ ([\ da-F] {1, 4} :) {7} [\ da-F] {1, 4} $/I. test (ipvalue) {isipv6 = true;} If (isipv6) {return true;} else {return false ;}} <input type = "text" name = "iporname" id = "iporname" style = "width: 80px; "value =" "/> <input name =" Submit "type =" button "value =" verify IPv6 "onclick = alert (querydev (iporname. value) style = "width: 80px"/>
========================================================== ========================================================== ========================================================== ============== Java verifies IPv4, IPv6 address/***** @ Param IP * @ return */public static Boolean validata_ipv6 (string host) {inetaddress addressipv6 = NULL; inet6address IPv6 = NULL; inet4address IPv4 = NULL; try {addressipv6 = inetaddress. getbyname (host);} catch (unknownhostexception e) {e. printstacktrace (); Return false;} If (addressipv6 instanceof inet6address) {IPv6 = (inet6address) addressipv6; return true;} If (addressipv6 instanceof inet4address) {return false ;} return true;} IPv4:/***** @ Param IP * @ return */public static Boolean validata_ipv4 (string host) {inetaddress addressipv4 = NULL; inet6address IPv6 = NULL; inet4address IPv4 = NULL; try {addressipv4 = inetaddress. getbyname (host);} catch (unknownhostexception e) {e. printstacktrace (); Return false;} If (addressipv4 instanceof inet6address) {IPv6 = (inet6address) failed; return false;} If (addressipv4 instanceof inet4address) {IPv4 = (inet4address) addressipv4; return true;} return true ;} ========================================================== ========================================================== ========================================================== ============== Java verifies IPv4, IPv6 address/***** @ Param IP * @ return */public static Boolean validata_ipv6 (string host) {inetaddress addressipv6 = NULL; inet6address IPv6 = NULL; inet4address IPv4 = NULL; try {addressipv6 = inetaddress. getbyname (host);} catch (unknownhostexception e) {e. printstacktrace (); Return false;} If (addressipv6 instanceof inet6address) {IPv6 = (inet6address) addressipv6; return true;} If (addressipv6 instanceof inet4address) {return false ;} return true;} IPv4:/***** @ Param IP * @ return */public static Boolean validata_ipv4 (string host) {inetaddress addressipv4 = NULL; inet6address IPv6 = NULL; inet4address IPv4 = NULL; try {addressipv4 = inetaddress. getbyname (host);} catch (unknownhostexception e) {e. printstacktrace (); Return false;} If (addressipv4 instanceof inet6address) {IPv6 = (inet6address) failed; return false;} If (addressipv4 instanceof inet4address) {IPv4 = (inet4address) addressipv4; return true;} return true ;}