Skip to content

Instantly share code, notes, and snippets.

@JamoCA
Last active April 9, 2020 13:36
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save JamoCA/94f1deb62257680ad93dbd000fe0d37f to your computer and use it in GitHub Desktop.
Save JamoCA/94f1deb62257680ad93dbd000fe0d37f to your computer and use it in GitHub Desktop.
ColdFusion UDF to test string to determine if valid IP address or not.
<!--- 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