指定与 C# 中的 TCPClient / Socket 一起使用的传出 IP 地址

发布于 2024-08-16 16:23:48 字数 238 浏览 7 评论 0原文

我的服务器有多个分配给网络适配器的 IP 地址。

该服务器上有一个客户端应用程序,用于通过 TCPClient 连接到另一个服务器应用程序。对于所有传出通信,我的服务器都使用默认 IP 地址,但是对于这个应用程序,我希望传出通信在另一个本地 IP 地址上发送。

通信时是否可以指定另一个本地分配的IP?

我正在尝试让远程服务器应用程序认为它来自另一个IP,因此它将通过防火墙等......

提前致谢

I've a server with several IP Addresses assigned to the network adapter.

On that server is a client app to connect to another server app via TCPClient. For all outgoing communications my servers default IP address is being used, however for this one application I'd like the outgoing communication to be send out on another local IP address.

Is it possible when communicating out to specify another locally assigned IP?

I'm trying to make the remote server app think it's from another IP so it will pass through firewalls etc....

Thanks in advance

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

寄与心 2024-08-23 16:23:48

您可以使用接受本地终结点地址的 TcpClient 构造函数:

TcpClient c=new TcpClient(new System.Net.IPEndPoint(...));

例如:

TcpClient c=new TcpClient(new IPEndPoint(IPAddress.Parse("192.168.1.1"), 0);

参考:TcpClient 构造函数 (IPEndPoint)

You can use the constructor of TcpClient that accepts a local endpoint address:

TcpClient c=new TcpClient(new System.Net.IPEndPoint(...));

For example:

TcpClient c=new TcpClient(new IPEndPoint(IPAddress.Parse("192.168.1.1"), 0);

Reference: TcpClient Constructor (IPEndPoint)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文