阻止网络服务器中的IP [英] Block IP in webserver

查看:93
本文介绍了阻止网络服务器中的IP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨!



我创建了一个(GUI)Web服务器,想要添加一个阻止IP的功能。



被阻止的IP列表存储在listView2中



Hi!

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);
listView1.Items.Add(listViewItem);
listViewItem.ForeColor = Color.Lime;
return;

// 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 "1.2.3.4" , but RemoteEndPoint IP is like "1.2.3.4:12345)
//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
SendString(keelatud,Client,"banned")

Thanks!
hope you understood!

推荐答案

听起来你真的没有写在网络服务器上,而是使用别人的代码,你不明白。如果你写了它,这对你来说实现起来是微不足道的。



你在上面的代码注释中的比较只是归结为简单的字符串操作来获得IP地址然后将两个字符串相互比较。
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.


这篇关于阻止网络服务器中的IP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆