Banning an IP programatically?

G

Guest

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
machine.config that I can redirect a 'banned' IP to a specific page?
 
G

Guest

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.
 
M

Michael Phillips, Jr.

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
 
G

Guest

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.
 
R

Richard Blewett [DevelopMentor]

Brian Kitt said:
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.

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top