C# 遍历本地网络

时间:2023-12-31 14:57:15
public static bool IsHNetCfgWayConnected(string opName)
{
NetSharingManagerClass netSharingMgr = new NetSharingManagerClass(); INetSharingEveryConnectionCollection connections = netSharingMgr.EnumEveryConnection;
List<object> conns = new List<object>();
foreach (INetConnection connection in connections)
{
INetConnectionProps connProps = netSharingMgr.get_NetConnectionProps(connection);
if (connProps.MediaType == tagNETCON_MEDIATYPE.NCM_LAN)
{
if (connProps.Name.Equals(opName))
{
return connProps.Status == tagNETCON_STATUS.NCS_CONNECTED;
} }
}
return false;
}