all groups > c# > october 2005 >
You're in the

c#

group:

Banning an IP programatically?



Banning an IP programatically? Brian Kitt
10/28/2005 10:08:02 PM
c#: I know how to ban an IP from the firewall. Is there some slick way to code a
trap on my website to check IP and redirect them to a 'banned' page? That
way they have the option to contact me if they are legitimate (via contact
information on that page). I know that I could, at the top of every single
page, check a ban list. Is there some slicker way through web.config or
Re: Banning an IP programatically? Brian Kitt
10/29/2005 11:32:07 AM
Actually, I would need the remote address, not the host address. I am
already grabbing the remote address so I can determine which IP's are bugging
me. I was hoping there was a slick way of redirecting that single IP to only
one page on my site.

[quoted text, click to view]
Re: Banning an IP programatically? Ollie Riches
10/29/2005 11:50:06 AM
this might help you:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemwebhttprequestclassuserhostaddresstopic.asp

HTH

Ollie Riches
[quoted text, click to view]

Re: Banning an IP programatically? Michael Phillips, Jr.
10/29/2005 3:48:25 PM
You can use the Request.ServerVariables("REMOTE_ADDR")
to get the remote address. You can redirect or add to a banned list.

You can add the ip address to the .htaccess file programatically
with simple file io. You can also use the method outlined in the
code project article below:

http://www.codeproject.com/csharp/IISWMI.asp

[quoted text, click to view]

Re: Banning an IP programatically? Brian Kitt
10/29/2005 4:03:03 PM
I had not heard of htaccess before, so I did some digging. Sorry, I'm on IIS.

htaccess is an Apache thing, not an NT thing. There are similar capabilities
for NT servers, though in my professional experience and personal opinion,
NT's ability in these areas is severely handicapped. But that's not what
we're here for.


[quoted text, click to view]
Re: Banning an IP programatically? Richard Blewett [DevelopMentor]
10/30/2005 9:16:58 AM
[quoted text, click to view]

You could also write a module to send that IP address (or keep a banned list
of IP addresses) a 404. I do something similar on my blog to counter
referrer spam

Regards

Richard Blewett - DevelopMentor
http://www.dotnetconsult.co.uk/weblog
http://www.dotnetconsult.co.uk

AddThis Social Bookmark Button