Telnet from multiple servers

Posted by Sharpcnet under C# on 6/3/2015 | Points: 10 | Views : 342 | Status : [Member] | Replies : 1
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 = "";
var centralPort = 25;

var servers = ",,";
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.


Posted by: Jitendrasoft09 on: 6/7/2015 [Member] [MVP] Starter | Points: 25


Make sure you have enabled the telnet client in your central server and you have to add the code to get the response status after sending telenet command and display the status of telnet successfully or not.

Refer below link for the details-

Jitendra Kumar
If my post helps you, plz mark as an answer.

Sharpcnet, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response