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 = "220.127.116.11,18.104.22.168,22.214.171.124";
var telnetPort = 23;
foreach (var server in servers.Split(','))
TcpClient tc = null;
tc = new TcpClient(server, telnetPort);
tc.Client.Send(System.Text.Encoding.ASCII.GetBytes("telnet " + centralServer + " " + centralPort));
catch (SocketException se)
// telnet failed on 'server'
if (tc != null)
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.