如何使用 C# 判断正在使用多个网卡中的哪一个?
如果我在客户端系统中有多个网卡(这样也会有多个IP地址),我如何知道在C#中使用哪个客户端IP与服务器通信? 我想要获取私有IP(不是公共IP)。
OR
请耐心阅读详细信息...
假设我的PC上连接了多个网卡,我如何知道使用哪张网卡进行通信。例如,如果我使用,
ping 192.168.x.xxx
我想知道使用哪张卡(以及哪个 IP 地址)进行通信。
该命令
netstat
将告诉我们有关活动连接的信息。我对活动连接不感兴趣,但我想知道下次连接将使用哪张卡。也就是说,如果我们使用 ping
将使用哪张卡(或 IP 地址)?
如何使用 C# 获得相同的 IP 地址(因为我想在 WCF 中做一些需要端点 IP 地址的事情)?
例如,我想使用 IP(如 LocalIP)和端口(如 ListeningPort)来创建以下
net.tcp:// + LocalIP + ":" + ListeningPort + "/Service/ep1;
查询的参考可以在... https://superuser.com/ questions/304372/how-can-i-tell-which-of-multiple-network-cards-is-in-use
How can I know which client IP is used for communication to the server in C# if I have multiple network cards in client system (so that there will be multiple IP addresses too) ?
I would like to get private IP (not the public IP) .
OR
Please be patient to read the details...
Suppose I have multiple network cards connected to my PC, how can I know which card is used for communication. For example, if I use
ping 192.168.x.xxx
I would like to know which card (and which IP address) used for communication.
The command
netstat
will tell us about the active connections. I am not interested in active connections, but I would like to know which card will be used for next connection. That is, if we use ping
which card (or IP address) will be used ?
How can I get the same IP address using C# (because I would like to do some stuff in WCF which needs endpoint IP addresses )?
For example, I would like to use the IP(as LocalIP) and port(as ListeningPort) to create the following
net.tcp:// + LocalIP + ":" + ListeningPort + "/Service/ep1;
A reference of the query can be found at...
https://superuser.com/questions/304372/how-can-i-tell-which-of-multiple-network-cards-is-in-use
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用 Socket 连接到远程主机使用 Bind 方法设置特定 IP 地址。
You can connect to remote host using Socket and set specific IP address using Bind method.