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!

Banning IPs

Status
Not open for further replies.

Guest_imported

New member
Joined
Jan 1, 1970
Messages
0
Does anyone know of a method to ban IP's using coldfusion? I'm sure I could put the IP in a database then see if it matches #CGI.REMOTE_ADDR#, however, what if I need to do it by the first two, or first three digits of their IP?

Any help would be great appreciated.
 
You can process #cgi.remote_addr# as a string:


<CFIF left(cgi.remote_addr,3) contains &quot;192&quot;>
Sorry, Charlie.
<CFABORT>
</CFIF>

HTH,
Phil Hegedusich
iimaksmall.gif
 
Ok... What if some peopel are going to be banned by the full IP while others will be banned bu a subnet. Is there any way? I know it's confusing, here's an example:

Tom (not banned) - 153.2.2.78
Jerry (banned) - 153.2.2.5
Susan (banned) - 153.2.7.5

Now, in my ban database I have the following:

153.2.2.5
153.2.7.*

Does this make any since?
 
I would construct a rule from the ban database. If the code encounters an asterisk in the ban field, it should construct a string that includes the address up to the subnet mask:

<Cfquery name=&quot;mybannedips&quot; datasource=&quot;ofs&quot;>
select ip_addr from bannedips
</CFQUERY>
<cfset banstring=&quot;&quot;>
<cfoutput query=&quot;mybannedips&quot;>
<cfif find(&quot;*&quot;,ip_addr)>
<cfset banstring = banstring & mid(ip_addr,1,find(&quot;*&quot;,ip_addr)-1)&&quot;,&quot;>
<cfelse>
<cfset banstring = banstring & ip_addr & &quot;,&quot;>
</cfif>
</cfoutput>
<cfset banstring = mid(banstring,1,len(banstring)-1)>
<cfoutput>#banstring#</cfoutput> is our list of bad boys.<br><br>
<!---Now, you can compare the entire remote address to the values in banstring. --->

<cfset testip = &quot;153.2.2.5&quot;>
<cfloop index=&quot;badboy&quot; list=&quot;#banstring#&quot;>
<cfif right(badboy,1) is &quot;.&quot;>
<cfif testip contains badboy>
<cfoutput>#testip#</cfoutput> is a Group Loser.<br>
</cfif>
<cfelse>
<cfif trim(testip) is trim(badboy)>
<cfoutput>#testip#</cfoutput> is a Lone Loser.<br>
</cfif>
</cfif>
</cfloop>

HTH,
Phil Hegedusich
iimaksmall.gif
 
Thanks alot. I knew there was a way I am just too new to CF to be able to figure it out.

Once again, thanks for your help.
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Sponsor

Back
Top