/// <summary> /// Get the SwitchType using IP Address of the Network Switch /// </summary> /// <param name="ipAddress">IP Address of Network Switch</param> /// <returns><see cref="SwitchType"/></returns> private static SwitchType GetSwitchType(IPAddress ipAddress) { TelnetIpc telnet = new TelnetIpc(ipAddress.ToString(), 23); SwitchType switchType = SwitchType.None; try { telnet.Connect(); telnet.SendLine(" "); Thread.Sleep(1000); // This command is tested currently only for HP ProCurve switch, need to check for other switches how it behaves telnet.SendLine("show config"); Thread.Sleep(3000); string data = telnet.ReceiveUntilMatch("$"); // HP manufactured switch can contain any of the strings. // ProCurve, Hewlett-Packard, Hewlett Packard if (data.Contains("ProCurve", StringComparison.CurrentCultureIgnoreCase) || data.Contains("Hewlett-Packard", StringComparison.CurrentCultureIgnoreCase) || data.Contains("Hewlett Packard", StringComparison.CurrentCultureIgnoreCase)) { switchType = SwitchType.HPProCurve; } } finally { telnet.Dispose(); Thread.Sleep(1000); } return(switchType); }
/// <summary> /// Get the RouterType using IP Address of the Router. /// </summary> /// <param name="ipAddress">IP Address of the Router.</param> /// <param name="userName">User name credentials to the router.</param> /// <param name="password">Password credentials to the router.</param> /// <returns><see cref="RouterType"/></returns> private static RouterType GetRouterType(IPAddress ipAddress, string userName, string password) { TelnetIpc telnet = new TelnetIpc(ipAddress.ToString(), 23); RouterType routerType = RouterType.None; try { telnet.Connect(); telnet.SendLine(" "); Thread.Sleep(TimeSpan.FromSeconds(5)); telnet.SendLine(userName); Thread.Sleep(TimeSpan.FromSeconds(5)); telnet.SendLine(password); Thread.Sleep(TimeSpan.FromSeconds(20)); string data = telnet.ReceiveUntilMatch("$"); // HP manufactured router can contain any of the strings. // ProCurve, Hewlett-Packard, Hewlett Packard if (data.Contains("ProCurve", StringComparison.CurrentCultureIgnoreCase) || data.Contains("Hewlett-Packard", StringComparison.CurrentCultureIgnoreCase) || data.Contains("Hewlett Packard", StringComparison.CurrentCultureIgnoreCase)) { routerType = RouterType.HP; } } finally { telnet.Dispose(); Thread.Sleep(1000); } return(routerType); }