static void Main(string[] args) { //new connection var con = new TelnetClient(FromConfig.Server, 23, 30); try { if (!con.Login(FromConfig.Username, FromConfig.Password)) { throw new Exception("Failed to connect."); } Console.WriteLine("In"); con.SendAndWait("cd /", "$"); con.SendAndWait("ls -ltr", "$"); Console.WriteLine(con.SessionLog); con.Disconnect(); Console.ReadLine(); } catch (Exception ex) { Console.WriteLine(con.SessionLog); Console.WriteLine(ex.Message); } }
public override Server creack(String ip, int port, String username, String password, int timeOut) { TelnetClient tc = null; Server server = new Server(); try { tc = new TelnetClient(ip, port); String s = tc.Login(username, password, timeOut * 1000); String prompt = s.TrimEnd(); prompt = s.Substring(prompt.Length - 1, 1); server.banner = prompt; if (prompt != "$" && prompt != ">") { return(server); } if (tc.IsConnected) { server.isSuccess = true;; } } catch (Exception e) { throw e; } finally { if (tc != null) { tc.Dispose(); } } return(server); }