Which Ethernet card is being used?

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)
 
S

Sherif ElMetainy

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top