Which Ethernet card is being used?

  • Thread starter Thread starter Ray Mitchell
  • Start date Start date
R

Ray Mitchell

Hello,

If I have several ethernet adaptors with different IP addresses on my system
and do the following (or something similar to an arbitrary non-Internet IP
address), how do I know or control which of those cards is being used?

TcpClient tcpClientB = new TcpClient("www.contoso.com", 11000);

Thanks,
Ray Mitchell
(e-mail address removed)
 
Hello

The TcpClient class has an overloaded constructor that takes an EndPoint as
a parameter

TcpClient tcpClientB = new TcpClient(new
IPEndPoint(IPAddress.Parse("10.0.0.1", 0)));
tcpClientB.Connect("www.contoso.com", 11000);

using this constructor you can control which local IP address is used,
therefore you can control which network card is used.

to know which ip address is used use this after the connection is made.
IPAddress ipAddr = ((IPEndPoint)tcpClientB.Client.LocalEndPoint).Address;

Best regards,
Sherif
 
Back
Top