There is a list of servers, each of which needs to be able to telnet to the central server - and I want to check if they can, from a single place.
The idea is to have a console application run from a single place which will check for all listed servers.Here is my code.
var centralServer = "10.20.30.100";
var centralPort = 25;
var servers = "11.12.13.201,11.12.13.202,11.12.13.203";
var telnetPort = 23;
foreach (var server in servers.Split(','))
{
TcpClient tc = null;
try
{
tc = new TcpClient(server, telnetPort);
tc.Client.Send(System.Text.Encoding.ASCII.GetBytes("telnet " + centralServer + " " + centralPort));
}
catch (SocketException se)
{
// telnet failed on 'server'
}
finally
{
if (tc != null)
{
tc.Close();
}
}
}
Even if the centralserver or centralport is invalid/incorrect, no exception occurs. The code still proceeds to complete the for loop . I am unable to know if a server was able to successfully telnet. How should I proceed further.