Guest_imported
New member
- Jan 1, 1970
- 0
I'm currently using IP banning code to re-direct users to a specified webpage. I've got it working using * for wildcards however I now have the need to use ? for just one digit of the ip address, where a * blocks a whole octet.
For example:
127.7.* blocks anyone connecting with a starting string of 127.7
Now I have the need to do something like 127.7.1??.2, which will need to block anyone with any number in the ? field. Not sure if this is possible, at any rate, here is my current code:
<!--- Check to see if their IP is banned. --->
<cfquery name="BannedIPS" datasource="#datasource#">
SELECT IP
FROM Banned_IPs
</cfquery>
<cfset banstring = "">
<cfoutput query="BannedIPs">
<cfif find("*",IP)>
<cfset banstring = banstring & mid(IP,1,find("*",IP)-1)&",">
<cfelse>
<cfset banstring = banstring & IP & ",">
</cfif>
</cfoutput>
<cfset banstring = mid(banstring,1,len(banstring)-1)>
<!---Now, you can compare the entire remote address to the values in banstring. --->
<cfset userip = "#CGI.REMOTE_ADDR#">
<cfloop index="banned" list="#banstring#">
<cfif right(banned,1) is ".">
<cfif userip contains banned>
<cflocation addtoken="No" url="banned.html">
</cfif>
<cfelse>
<cfif trim(userip) is trim(banned)>
<cflocation addtoken="No" url="banned.html">
</cfif>
</cfif>
</cfloop>
For example:
127.7.* blocks anyone connecting with a starting string of 127.7
Now I have the need to do something like 127.7.1??.2, which will need to block anyone with any number in the ? field. Not sure if this is possible, at any rate, here is my current code:
<!--- Check to see if their IP is banned. --->
<cfquery name="BannedIPS" datasource="#datasource#">
SELECT IP
FROM Banned_IPs
</cfquery>
<cfset banstring = "">
<cfoutput query="BannedIPs">
<cfif find("*",IP)>
<cfset banstring = banstring & mid(IP,1,find("*",IP)-1)&",">
<cfelse>
<cfset banstring = banstring & IP & ",">
</cfif>
</cfoutput>
<cfset banstring = mid(banstring,1,len(banstring)-1)>
<!---Now, you can compare the entire remote address to the values in banstring. --->
<cfset userip = "#CGI.REMOTE_ADDR#">
<cfloop index="banned" list="#banstring#">
<cfif right(banned,1) is ".">
<cfif userip contains banned>
<cflocation addtoken="No" url="banned.html">
</cfif>
<cfelse>
<cfif trim(userip) is trim(banned)>
<cflocation addtoken="No" url="banned.html">
</cfif>
</cfif>
</cfloop>