问题描述
电脑只有一个网卡时可以直接获得,如果电脑有多个网卡,如何获得与服务器通信的那个网卡?而不是另外的几个?
解决方案
解决方案二:
我只是觉得39分比价有趣,就进来了。老帖子里有现成的。///<summary>///获得当前机器的活动中Mac地址,若无联网则返回空""///</summary>///<returns>mac地址,例如:18:03:73:AE:38:0D</returns>publicstaticstringGetActivatedAdaptorMacAddress(){stringmac="";ManagementClassmc=newManagementClass("Win32_NetworkAdapterConfiguration");ManagementObjectCollectionmoc=mc.GetInstances();foreach(ManagementObjectmoinmoc){if(mo["IPEnabled"].ToString()=="True"){mac=mo["MacAddress"].ToString();}}returnmac;}
解决方案三:
privatevoidbtnSearch_Click(objectsender,EventArgse){System.Net.NetworkInformation.IPGlobalPropertiesnetwork=System.Net.NetworkInformation.IPGlobalProperties.GetIPGlobalProperties();System.Net.NetworkInformation.TcpConnectionInformation[]connections=network.GetActiveTcpConnections();foreach(System.Net.NetworkInformation.TcpConnectionInformationconnectioninconnections){}}