public NetworkInfo FetchLocalNetworkInfo(DetectionInfo info) { if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { LogIPConfig(); } //Get the network information with SUTIpList NetworkInfo networkInfo = info.networkInfo; #region Get Local IP List networkInfo.LocalIpList = new List <IPAddress>(); foreach (NetworkInterface adapter in NetworkInterface.GetAllNetworkInterfaces()) { if (adapter.OperationalStatus != OperationalStatus.Up) { continue; } if (adapter.NetworkInterfaceType == NetworkInterfaceType.Ethernet || adapter.NetworkInterfaceType == NetworkInterfaceType.Wireless80211 || adapter.NetworkInterfaceType == NetworkInterfaceType.GigabitEthernet) { foreach (var ip in adapter.GetIPProperties().UnicastAddresses) { if (ip.Address.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork) { using (Smb2Client smb2Client = new Smb2Client(new TimeSpan(0, 0, defaultTimeoutInSeconds))) { try { smb2Client.ConnectOverTCP(SUTIpAddress, ip.Address); networkInfo.LocalIpList.Add(ip.Address); } catch (Exception ex) { logWriter.AddLog( DetectLogLevel.Information, string.Format("Connect from client IP {0} to SUT IP {1} failed, reason: {2}", ip.Address, SUTIpAddress, ex.Message)); } } } } } } if (networkInfo.LocalIpList.Count == 0) { logWriter.AddLog(DetectLogLevel.Error, "No available local IP address"); } #endregion return(networkInfo); }
public NetworkInfo DetectSUTConnection() { NetworkInfo networkInfo = new NetworkInfo(); IPAddress address; //Detect SUT IP address by SUT name //If SUT name is an ip address, skip to resolve, use the ip address directly try { if (IPAddress.TryParse(sutName, out address)) { networkInfo.SUTIpList = new List <IPAddress>(); networkInfo.SUTIpList.Add(address); } else //DNS resolve the SUT IP address by SUT name { IPAddress[] addList = Dns.GetHostAddresses(sutName); if (null == addList) { logWriter.AddLog(LogLevel.Error, string.Format("The SUT name {0} is incorrect.", SUTName)); } networkInfo.SUTIpList = new List <IPAddress>(); logWriter.AddLog(LogLevel.Information, "IP addresses returned from Dns.GetHostAddresses:"); foreach (var item in addList) { logWriter.AddLog(LogLevel.Information, item.ToString()); if (item.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork) { networkInfo.SUTIpList.Add(item); } } if (networkInfo.SUTIpList.Count == 0) { logWriter.AddLog(LogLevel.Error, string.Format("No available IP address resolved for target SUT {0}.", SUTName)); } } DetermineSUTIPAddress(networkInfo.SUTIpList.ToArray()); return(networkInfo); } catch { logWriter.AddLog(LogLevel.Error, string.Format("Detect Target SUT connection failed with SUT name: {0}.", SUTName)); return(null); } }
public NetworkInfo PingTargetSUT() { NetworkInfo networkInfo = new NetworkInfo(); IPAddress[] addList = Dns.GetHostAddresses(SUTName); if (null == addList) { logWriter.AddLog(LogLevel.Error, string.Format("The SUT name {0} is incorrect.", SUTName)); } networkInfo.SUTIpList = new List<IPAddress>(); logWriter.AddLog(LogLevel.Information, "IP addresses returned from Dns.GetHostAddresses:"); foreach (var item in addList) { logWriter.AddLog(LogLevel.Information, item.ToString()); if (item.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork) { networkInfo.SUTIpList.Add(item); } } if (networkInfo.SUTIpList.Count == 0) { logWriter.AddLog(LogLevel.Error, string.Format("No available IP address on target SUT {0}.", SUTName)); } DetermineSUTIPAddress(networkInfo.SUTIpList.ToArray()); return networkInfo; }