简体   繁体   English

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

[英]Specify the outgoing IP address to use with TCPClient / Socket in C#

I've a server with several IP Addresses assigned to the network adapter. 我有一台服务器,它为网络适配器分配了几个IP地址。

On that server is a client app to connect to another server app via TCPClient. 该服务器上有一个客户端应用程序,可通过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. 对于所有传出通信,我的服务器都使用默认IP地址,但是对于此应用程序,我希望将传出通信发送到另一个本地IP地址。

Is it possible when communicating out to specify another locally assigned IP? 通信时可以指定另一个本地分配的IP吗?

I'm trying to make the remote server app think it's from another IP so it will pass through firewalls etc.... 我试图使远程服务器应用程序认为它来自另一个IP,因此它将通过防火墙等。

Thanks in advance 提前致谢

You can use the constructor of TcpClient that accepts a local endpoint address: 您可以使用TcpClient的构造函数,该构造函数接受本地端点地址:

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) 参考: TcpClient构造函数(IPEndPoint)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM