Click here to Skip to main content
13,045,417 members (124,805 online)
Rate this:
Please Sign up or sign in to vote.
See more:

I have created a (GUI)web server and want to add a function that blocks an IP.

The list of blocked IP(s) are stored in listView2

SendString("<html>\n\n\t<meta http-equiv=\"Refresh\" content=\"0; url=" + Index + "\">\n\n</html>", Client, "200 OK"); //if client connects, then Server sends automatically index page
string[] row = { DateTime.Now.ToString(), Client.Client.RemoteEndPoint.ToString(), "Külastas (külastas means visited in English) :" + URL, "200" }; // 200 means code 200 OK
var listViewItem = new ListViewItem(row);
listViewItem.ForeColor = Color.Lime;
// but if client's IP is the same as IP in listView2, it should send string "You are blocked" or sth. like that. BUT THE PROBLEM IS:
// 1) blocked IP list has IP's like "" , but RemoteEndPoint IP is like "
//these are totally different, if I want to block an IP, I won't put down all the different ports...
// so how do I get ONLY the IP from remoteendpoint, not ports
// 2) if I get the (only)IP(not port) then server should compare the IP with blocked IP list.If Client's IP is listed in blocked IP list (listView2), then it sends string
hope you understood!
Posted 1-Apr-13 6:21am
Is it ASP.NET? Tag it. (Or a custom HTTP server, something else?)
It does not seem to make sense. Of course, you can always block some client IP addresses, as you have a client IP in HTTP request, but why would you have them in a list view which you show to the client?
Even if you show it, you should have some original data source with blocked IP, use it.

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

It sounds like you really didn'y write the web server, but instead used someone elses code that you don't understand. If you wrote it, this would be trivial for you to implement.

Your comparison in your code comments above just comes down to trivial string manipluations to get just the IP address and then comparing two string to each other.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170713.1 | Last Updated 1 Apr 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100