Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

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

like image 701
Dave Hogan Avatar asked Jan 06 '10 20:01

Dave Hogan


1 Answers

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)

like image 143
Aviad P. Avatar answered Oct 05 '22 12:10

Aviad P.