-
-
Save ivanionut/0fd5bcb04f368e52219faf2336f39202 to your computer and use it in GitHub Desktop.
ColdFusion UDF to test string to determine if valid IP address or not.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!--- 20190801 | |
ColdFusion UDF to test string to determine if valid IP address or not. | |
https://www.anujgakhar.com/2008/02/21/validate-ip-address-natively-with-coldfusion/ ---> | |
<cfscript> | |
function isValidIPAddress(inputString){ | |
var response = false; | |
var IPAddressUtils = createObject("java","coldfusion.util.IPAddressUtils"); | |
response = javacast("boolean", IPAddressUtils.validateIPAdress( javacast("string", arguments.inputString) )); | |
if (response and listfind("0.0.0.0,255.255.255.255", javacast("string", arguments.inputString))){ | |
response = false; | |
} | |
return response; | |
} | |
</cfscript> | |
<cfset TestIPS = ["123", "127.0.0.1", CGI.Remote_Addr, "10.0.0.1", "10,0,0,1", "256.0.0.23"]> | |
<h2>IP Test</h2> | |
<cfoutput> | |
<cfloop array="#TestIPs#" index="thisIP"> | |
<div>#thisIP# = #isValidIPAddress(thisIP)#</div> | |
</cfloop> | |
</cfoutput> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment