C#套接字 - 禁止IP [英] C# Sockets - Banning IP's

查看:128
本文介绍了C#套接字 - 禁止IP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,


我对C#中的套接字有疑问。我有一个服务器,我想阻止连接到禁止IP的客户端。两者都是用.NET 4.0制作的。 


服务器通过Internet(No-ip主机名)运行,而不仅仅是在本地网络中运行。问题是客户的IP每天都在变化,所以我不知道如何永久地禁止这些客户。我知道我可以通过简单地将
客户端的IP与任何被禁止的地址进行比较来禁止它们。

 if(banned_ip == clients_ip)
{
client.Disconnect();
}

但是如何获取客户端的IP我可以永久禁止?


如果您需要更多信息,我要张贴他们。



Joe

解决方案

如果您想获取客户端的IP,请使用
RemoteEndPoint属性
然后你可以强制转换
端点(父类)

IPEndPoint
并使用
地址属性

ToString
得到t他是IPv4或IPv6的好格式。



谢谢,


Brad


Hi guys,

I've got a question on Sockets in C#. I've got a Server which I want to prevent from connecting to clients where the IP was banned. Both are made with .NET 4.0 . 

The server is running via Internet (No-ip hostname), not just in a local network. The problem is that the IP of the clients is changing every day, so I don't know how to ban these clients permantly. I know that I can ban them by simply comparing the IP of the Client with any banned adress.

if ( banned_ip == clients_ip )
{
     client.Disconnect();
}

But how do I fetch the Client's IP I can ban permantly ?

If you need some more infos, I'm gonna post them.

Joe

解决方案

If you wanted to get the IP of the client then use the RemoteEndPoint Property of the socket and then you can cast that Endpoint (parent class) to an IPEndPointand use the Address property and the ToString to get the IPv4 or IPv6 nice format.

Thanks,

Brad


这篇关于C#套接字 - 禁止IP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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