How to telnet from remote server - c#
-
New to telnet. There is a list of servers and I need to check, if each server is able to successfully telnet a certain server(10.20.30.100) with port(25). The idea is to have a console application run from a single place which will check for all listed servers. Followed @freedomn-m's solution, but still stuck. 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.
-
Answer:
You won't 'command' remote server to open connection to telnet server and return result with your existing code. If servers themselves have telnet enabled, you can accomplish your task in 3 steps for each server: Open telnet connection to 'telnet client` server Send 'telnet client' server command to open telnet connection to 'telnet server' server Check if it succeeded. There is a http://www.codeproject.com/Articles/19071/Quick-tool-A-minimalistic-Telnet-library. But you'll be better off using some monitoring solution like http://www.zabbix.com/.
Qwerty at Stack Overflow Visit the source
Other answers
Consider how you would do this without code. As you've described this, you have a number of servers, each of which need to be able to telnet to the central server - and you want to check they can from a single place. Without code, you would telnet to the remote server, then, on that server, via your telnet client, send the telnet request to the destination server. (if using telnet alone, there are other ways such as RPC). You can't execute C# code on the remote server unless you deploy your/an app there (which is an option ofc). Updating your code: var centralServer = "10.20.30.100"; var centralPort = 25; // 25 as per OP 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)); // tc.Client.Receive } catch (SocketException se) { // telnet failed on 'server' } finally { if (tc != null) { tc.Close(); } } } As this question isn't about how to send/receive via telnet, I've left that for you to complete. In addition: there are a number of C# telnet libraries that make it much easier to connect/send commands/receive responses. Edit: Updated port to use telnet port. http://en.wikipedia.org/wiki/List_of_TCP_and_UDP_port_numbers The central server port may be 23 or 25 depending on original post.
freedomn-m
Related Q & A:
- How to write a parser in C?Best solution by Stack Overflow
- How to split a string in C++?Best solution by Stack Overflow
- How to send data from device to remote server?Best solution by Stack Overflow
- How to marshall a string in C?Best solution by Stack Overflow
- How can I get the remote server's date and time at the client side in my application in c#?Best solution by Stack Overflow
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.