Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

IP Banning Code...

Status
Not open for further replies.

Guest_imported

New member
Joined
Jan 1, 1970
Messages
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=&quot;BannedIPS&quot; datasource=&quot;#datasource#&quot;>
SELECT IP

FROM Banned_IPs

</cfquery>

<cfset banstring = &quot;&quot;>

<cfoutput query=&quot;BannedIPs&quot;>
<cfif find(&quot;*&quot;,IP)>
<cfset banstring = banstring & mid(IP,1,find(&quot;*&quot;,IP)-1)&&quot;,&quot;>
<cfelse>
<cfset banstring = banstring & IP & &quot;,&quot;>
</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 = &quot;#CGI.REMOTE_ADDR#&quot;>

<cfloop index=&quot;banned&quot; list=&quot;#banstring#&quot;>
<cfif right(banned,1) is &quot;.&quot;>
<cfif userip contains banned>
<cflocation addtoken=&quot;No&quot; url=&quot;banned.html&quot;>
</cfif>
<cfelse>
<cfif trim(userip) is trim(banned)>
<cflocation addtoken=&quot;No&quot; url=&quot;banned.html&quot;>
</cfif>
</cfif>
</cfloop>
 
Have you looked at using Regular Expressions? What are some of the IP patters you are trying to ban? - tleish
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top