static void Main(string[] args) { TelnetConnection tc = new TelnetConnection("localhost", 7777); String prompt = ""; while (tc.IsConnected && prompt.Trim() != "exit" ) { int i = 0; String serveroutput = tc.Read(); while (serveroutput.Length < 1) { Thread.Sleep(50); serveroutput = tc.Read(); i++; } serveroutput = serveroutput.Replace(">", ""); //serveroutput = serveroutput.StartsWith("", StringComparison.OrdinalIgnoreCase); Console.Write(serveroutput); serveroutput = "\bEDC>"; // send client input to server Console.Write(serveroutput); prompt = Console.ReadLine(); tc.WriteLine(prompt); } Console.WriteLine("***DISCONNECTED"); }
static void Main(string[] args) { //create a new telnet connection to hostname "gobelijn" on port "23" TelnetConnection tc = new TelnetConnection("gobelijn", 23); //login with user "root",password "rootpassword", using a timeout of 100ms, and show server output string s = tc.Login("root", "rootpassword",100); Console.Write(s); // server output should end with "$" or ">", otherwise the connection failed string prompt = s.TrimEnd(); prompt = s.Substring(prompt.Length -1,1); if (prompt != "$" && prompt != ">" ) throw new Exception("Connection failed"); prompt = ""; // while connected while (tc.IsConnected && prompt.Trim() != "exit" ) { // display server output Console.Write(tc.Read()); // send client input to server prompt = Console.ReadLine(); tc.WriteLine(prompt); // display server output Console.Write(tc.Read()); } Console.WriteLine("***DISCONNECTED"); Console.ReadLine(); }
static void Main(string[] args) { // var exploit = new WebExploiter("192.168.1.254", "8894501933"); // exploit.EnableBackdoor(true); var fixer=new ProblemFixer("192.168.1.254", 28, "8894501933"); fixer.DisableDhcp(); //fixer.FactoryReset(); return; //create a new telnet connection to hostname "gobelijn" on port "23" TelnetConnection tc = new TelnetConnection("192.168.1.254", 23); //login with user "root",password "rootpassword", using a timeout of 100ms, //and show server output string s = tc.Login("admin", "0387371392", 1000); Console.Write(s); // server output should end with "$" or ">", otherwise the connection failed string prompt = s.TrimEnd(); prompt = s.Substring(prompt.Length - 1, 1); if (prompt != "$" && prompt != ">") throw new Exception("Connection failed"); prompt = ""; // while connected while (tc.IsConnected) { // display server output Console.Write(tc.Read()); // send client input to server prompt = Console.ReadLine(); tc.WriteLine(prompt); // display server output Console.Write(tc.Read()); } Console.WriteLine("***DISCONNECTED"); Console.ReadLine(); }
static void Main(string[] args) { //create a new telnet connection to hostname "gobelijn" on port "23" TelnetConnection tc = new TelnetConnection("192.168.7.2", 23); //login with user "root",password "rootpassword", using a timeout of 100ms, and show server output string s = tc.Login("debian", "temppwd", 100); //Thread.Sleep(5000); Console.Write(s); // server output should end with "$" or ">", otherwise the connection failed string prompt = s.TrimEnd(); /* prompt = s.Substring(prompt.Length -1,1); * if (prompt != "$" && prompt != ">" ) * throw new Exception("Connection failed"); * * prompt = "";*/ // while connected string test; // display server output Console.Write(tc.Read()); tc.WriteLine("pwd"); Console.Write(tc.Read()); tc.WriteLine("cd evl/"); Console.Write(tc.Read()); tc.WriteLine("./run_Evlsrv.sh stdin"); Console.Write(tc.Read()); tc.WriteLine("openc"); Console.Write(tc.Read()); tc.WriteLine("set i 17260 1"); Console.Write(tc.Read()); tc.WriteLine("closec"); Console.Write(tc.Read()); tc.WriteLine("test ../letuan1/Function_test/C128/C128B/C128_B.bmp"); Console.Write(tc.Read()); tc.WriteLine("loop 0"); test = tc.Read(); Console.Write(tc.Read()); }
private void ProcessOutput() { if (!_tc.IsConnected) { return; } var s = _tc.Read(); s = Regex.Replace(s, @"\x1b\[([0-9,A-Z]{1,2}(;[0-9]{1,2})?(;[0-9]{3})?)?[m|K]?", ""); tbOutput.AppendText(s); }
/// <summary> /// Sends a pload command and returns the current and voltage values /// </summary> /// <param name="tc">Telnet connection to the EMber</param> /// <param name="board_type">What board are we using</param> /// <returns>Current/Voltage structure values</returns> static CS_Current_Voltage ember_parse_pinfo_registers(TelnetConnection tc) { string rawCurrentPattern = "Raw IRMS: ([0-9,A-F]{8})"; string rawVoltagePattern = "Raw VRMS: ([0-9,A-F]{8})"; double current_cs = 0.0; double voltage_cs = 0.0; string cmd = string.Format("cu {0}_pload", _cmd_prefix); traceLog(string.Format("Send cmd: {0}", cmd)); tc.WriteLine(cmd); Thread.Sleep(500); string datain = tc.Read(); Trace.WriteLine(datain); string msg; if (datain.Length > 0) { //traceLog(string.Format("Data received: {0}", datain)); // It gets log with "p_ember_isachan_OutputDataReceived" Match match = Regex.Match(datain, rawCurrentPattern); if (match.Groups.Count != 2) { msg = string.Format("Unable to parse pinfo for current. Output was:{0}", datain); throw new Exception(msg); } string current_hexstr = match.Groups[1].Value; int current_int = Convert.ToInt32(current_hexstr, 16); current_cs = regHex_ToDouble(current_int); current_cs = current_cs * _current_reference / 0.6; voltage_cs = 0.0; match = Regex.Match(datain, rawVoltagePattern); if (match.Groups.Count != 2) { msg = string.Format("Unable to parse pinfo for voltage. Output was:{0}", datain); throw new Exception(msg); } string voltage_hexstr = match.Groups[1].Value; int volatge_int = Convert.ToInt32(voltage_hexstr, 16); voltage_cs = regHex_ToDouble(volatge_int); voltage_cs = voltage_cs * _voltage_reference / 0.6; } else { msg = string.Format("No data recieved from telnet"); throw new Exception(msg); } CS_Current_Voltage current_voltage = new CS_Current_Voltage(i: current_cs, v: voltage_cs); return current_voltage; }
public void DisableDhcp() { //conn[1].dhcps-enable using (var telnet = new TelnetConnection(Address, Port)) { NshLogin(telnet); string output = telnet.Read(); Logger.Log("Sending set conn[1].dhcps-enable off"); telnet.WriteLine("set conn[1].dhcps-enable off"); SaveChanges(telnet); } }
public void DisableBridgeMode() { using (var telnet = new TelnetConnection(Address, Port)) { NshLogin(telnet); string output = telnet.Read(); Logger.Log("Sending set link[1].port-vlan.ports \"lan-1 lan-2 lan-3 lan-4 ssid-1 ssid-2 ssid-3 ssid-4\""); telnet.WriteLine("set link[1].port-vlan.ports \"lan-1 lan-2 lan-3 lan-4 ssid-1 ssid-2 ssid-3 ssid-4\""); Logger.Log("Sending set link[2].port-vlan.ports \"vc-1\""); telnet.WriteLine("set link[2].port-vlan.ports \"vc-1\""); SaveChanges(telnet); } }
static void Main(string[] args) { //create a new telnet connection to hostname "gobelijn" on port "23" TelnetConnection tc = new TelnetConnection("gobelijn", 23); //login with user "root",password "rootpassword", using a timeout of 100ms, and show server output string s = tc.Login("root", "rootpassword", 100); Console.Write(s); // server output should end with "$" or ">", otherwise the connection failed string prompt = s.TrimEnd(); prompt = s.Substring(prompt.Length - 1, 1); if (prompt != "$" && prompt != ">") { throw new Exception("Connection failed"); } prompt = ""; // while connected while (tc.IsConnected && prompt.Trim() != "exit") { // display server output Console.Write(tc.Read()); // send client input to server prompt = Console.ReadLine(); tc.WriteLine(prompt); // display server output Console.Write(tc.Read()); } Console.WriteLine("***DISCONNECTED"); Console.ReadLine(); }
/// <summary> /// Telnets to the Ember and prints custom commands /// Parses command list and tries to find the pload or pinfo comand prefix /// It is usually "cs5480_" in the case of SPDI or "cs5490_" in the case of UART comunications /// Exception is thrown if not pload command is found after typing "cu" /// </summary> /// <returns></returns> public static string Get_Custom_Command_Prefix(TelnetConnection telnet_connection) { string cmd_pre = null; int try_count = 0; string data = ""; TCLI.Wait_For_Prompt(telnet_connection); while (true) { telnet_connection.WriteLine("cu"); data += telnet_connection.Read(); if (data.Contains("pload")) break; if (try_count++ > 3) break; } string msg = ""; if (!data.Contains("pload")) { msg = string.Format("Unable to find pload command from custom command output list from Ember. Output was: {0}", data); throw new Exception(msg); } string pattern = @"(cs[0-9]{4})_pload\r\n"; Match match = Regex.Match(data, pattern); if (match.Groups.Count != 2) { msg = string.Format("Unable to parse custom command list for pload. Output was:{0}", data); throw new Exception(msg); } cmd_pre = match.Groups[1].Value; return cmd_pre; }
/// <summary> /// Sends a pload command and returns the current and voltage values /// </summary> /// <param name="telnet_connection">Already opened Telnet connection to the Ember</param> /// <param name="board_type">What board are we using</param> /// <returns>Current/Voltage structure values</returns> public static Current_Voltage Parse_Pload_Registers( TelnetConnection telnet_connection, string cmd_prefix, double voltage_ac_reference, double current_ac_reference) { string rawCurrentPattern = "Raw IRMS: ([0-9,A-F]{8})"; string rawVoltagePattern = "Raw VRMS: ([0-9,A-F]{8})"; double current_cs = 0.0; double voltage_cs = 0.0; TCLI.Wait_For_Prompt(telnet_connection); string cmd = string.Format("cu {0}_pload", cmd_prefix); telnet_connection.WriteLine(cmd); Thread.Sleep(500); string datain = telnet_connection.Read(); Trace.WriteLine(datain); TCLI.Wait_For_Prompt(telnet_connection); string msg; if (datain != null && datain.Length > 0) { Match on_off_match = Regex.Match(datain, "Changing OnOff .*"); if (on_off_match.Success) { msg = on_off_match.Value; } Match match = Regex.Match(datain, rawCurrentPattern); if (match.Groups.Count != 2) { msg = string.Format("Unable to parse pinfo for current. Output was:{0}", datain); throw new Exception(msg); } string current_hexstr = match.Groups[1].Value; int current_int = Convert.ToInt32(current_hexstr, 16); current_cs = RegHex_ToDouble(current_int); current_cs = current_cs * current_ac_reference / 0.6; voltage_cs = 0.0; match = Regex.Match(datain, rawVoltagePattern); if (match.Groups.Count != 2) { msg = string.Format("Unable to parse pinfo for voltage. Output was:{0}", datain); throw new Exception(msg); } string voltage_hexstr = match.Groups[1].Value; int volatge_int = Convert.ToInt32(voltage_hexstr, 16); voltage_cs = RegHex_ToDouble(volatge_int); voltage_cs = voltage_cs * voltage_ac_reference / 0.6; } else { msg = string.Format("No data received after \"{0}\" command", cmd); throw new Exception(msg); } Current_Voltage current_voltage = new Current_Voltage(i: current_cs, v: voltage_cs); return current_voltage; }
void SaveChanges(TelnetConnection telnet) { telnet.WriteLine("validate"); string output=telnet.Read(); Assert(output.Contains("succeeded"), "Validation did not appear to be successful"); telnet.WriteLine("apply"); telnet.WriteLine("save"); output = telnet.Read(); //Assert(output.Contains("Saving the database"), "Settings did not appear to be properly saved to persistent database"); Logger.Log("Changes Saved"); }
void NshLogin(TelnetConnection telnet) { Logger.Log("Logging in as admin.."); string output=telnet.Login("admin", Password, 2000); if (output.Contains("Login incorrect")) { Logger.Log("Got incorrect login message! Ensure that you typed the correct access code!"); throw new ApplicationException("Can not reach nsh shell"); } output = telnet.Read(); telnet.WriteLine(""); //because apparently it doesn't always print the prompt otherwise output = telnet.Read(3000); Assert(output.Contains("Axis"), "nsh shell does not appear to be working... or something"); }
public static Tokens Parse_Pinfo_Tokens( TelnetConnection telnet_connection, string cmd_prefix) { string vfactorPattern = "Voltage Factor: ([\\d]+)"; string ifactorPattern = "Current Factor: ([\\d]+)"; string vgainTokenPattern = "VGain Token\\s0x([0-9,A-F]{8})"; string igainTokenPattern = "IGain Token\\s0x([0-9,A-F]{8})"; string cmd = string.Format("cu {0}_pinfo", cmd_prefix); telnet_connection.WriteLine(cmd); Thread.Sleep(500); string datain = telnet_connection.Read(); Trace.WriteLine(datain); string msg; Tokens tokens = new Tokens(); if (datain != null && datain.Length > 0) { Match match = Regex.Match(datain, vfactorPattern); if (match.Groups.Count != 2) { msg = string.Format("Unable to parse pinfo for Voltage Factor. Output was:{0}", datain); throw new Exception(msg); } tokens.VoltageFactor = Convert.ToInt32(match.Groups[1].Value, 10); match = Regex.Match(datain, ifactorPattern); if (match.Groups.Count != 2) { msg = string.Format("Unable to parse pinfo for Current Factor. Output was:{0}", datain); throw new Exception(msg); } tokens.CurrentFactor = Convert.ToInt32(match.Groups[1].Value, 10); match = Regex.Match(datain, vgainTokenPattern); if (match.Groups.Count != 2) { msg = string.Format("Unable to parse pinfo for VGain Token. Output was:{0}", datain); throw new Exception(msg); } tokens.VoltageGainToken = Convert.ToInt32(match.Groups[1].Value, 16); match = Regex.Match(datain, igainTokenPattern); if (match.Groups.Count != 2) { msg = string.Format("Unable to parse pinfo for IGain Token. Output was:{0}", datain); throw new Exception(msg); } tokens.CurrentGainToken = Convert.ToInt32(match.Groups[1].Value, 16); } else { msg = string.Format("No data received after \"{0}\" command", cmd); throw new Exception(msg); } return tokens; }
/// <summary> /// Waits for output /// </summary> /// <param name="telnet_connection"></param> /// <param name="expected_data"></param> /// <param name="timeout_ms"></param> /// <param name="sample_ms"></param> /// <returns></returns> public static string Wait_For_String(TelnetConnection telnet_connection, string expected_data, int timeout_ms, int sample_ms = 250) { int total_wait = 0; string data = ""; while (total_wait < timeout_ms) { data += telnet_connection.Read(); if (data.Contains(expected_data)) break; Thread.Sleep(sample_ms); total_wait += sample_ms; } if (!data.Contains(expected_data)) { string msg = string.Format("Telnet session timeout after {0} ms waiting for data \"{1}\". Data was: \"{2}\"", total_wait, expected_data, data); throw new Exception(msg); } return data; }
/// <summary> /// Just a wrapper that reads and returns the telnet data /// </summary> /// <param name="telnet_connection"></param> /// <returns></returns> public static string Read(TelnetConnection telnet_connection) { return telnet_connection.Read(); }
public static Match Wait_For_Match(TelnetConnection telnet_connection, string command, string pattern, int retry_count = 3, int delay_ms = 100) { Wait_For_Prompt(telnet_connection); int n = 0; string data = ""; Match match; while (n < retry_count) { telnet_connection.WriteLine(command); Thread.Sleep(delay_ms); data = telnet_connection.Read(); if (data != null) { match = Regex.Match(data, pattern); if (match.Success) { return match; } } n++; } string msg = string.Format("Telnet session data not match found after command \"{0}\". Expected: \"{1}\". Received: \"{2}\"", command, pattern, data); throw new Exception(msg); }
private GrabResult GrabFTP(string serverAddr) { string result; try { TelnetConnection tc = new TelnetConnection(serverAddr, 21); result = tc.Read(); } catch (Exception) { throw new Exception("Service is closed!"); } return GetFTPKnownOS(result); }
/// <summary> /// Gets the EUI /// </summary> /// <param name="telnet_connection"></param> /// <returns></returns> public static string Get_EUI(TelnetConnection telnet_connection) { string eui = null; int try_count = 0; string datain = ""; string pattern = Regex.Escape("node [(>)") + "([0-9,A-F]{16})" + Regex.Escape("]"); TCLI.Wait_For_Prompt(telnet_connection); while (true) { telnet_connection.WriteLine("info"); Thread.Sleep(500); datain = telnet_connection.Read(); if (datain != null && datain.Length > 0 && Regex.Match(datain, pattern).Groups.Count == 2) break; if (try_count++ > 3) break; } if (datain != null && datain.Length > 0) { Match match = Regex.Match(datain, pattern); if (match.Groups.Count != 2) { string msg = string.Format("Unable to parse info EUI. Output was:{0}", datain); throw new Exception(msg); } eui = match.Groups[1].Value; } else { string msg = string.Format("No data received after \"Info\" command"); throw new Exception(msg); } return eui; }
/// <summary> /// Sends a command and waits for specific message to be returned /// </summary> /// <param name="telnet_connection"></param> /// <param name="command"></param> /// <param name="expected_data"></param> /// <param name="retry_count"></param> /// <param name="delay_ms"></param> public static string Wait_For_String(TelnetConnection telnet_connection, string command, string expected_data, int retry_count = 3, int delay_ms = 100) { Wait_For_Prompt(telnet_connection); int n = 0; string data = ""; while (n < retry_count) { telnet_connection.WriteLine(command); Thread.Sleep(delay_ms); data = telnet_connection.Read(); if (data != null) { if (data.Contains(expected_data)) { break; } } n++; } if (!data.Contains(expected_data)) { string msg = string.Format("Telnet session incorrect data after command \"{0}\". Expected: \"{1}\". Received: \"{2}\"", command, expected_data, data); throw new Exception(msg); } return data; }
public string DumpInfo() { StringBuilder output = new StringBuilder(10 * 1024); using (var telnet = new TelnetConnection(Address, Port)) { NshLogin(telnet); output.AppendLine(telnet.Read()); Logger.Log("Sending dump command"); telnet.WriteLine("dump"); Thread.Sleep(500); output.AppendLine(telnet.Read(1000)); Logger.Log("Sending mfg command"); telnet.WriteLine("mfg show"); Thread.Sleep(500); output.AppendLine(telnet.Read(1000)); // Assert(output.Contains("the factory defaults"), "Factory Reset request did not appear to succeed"); Logger.Log("Done receiving configuration data"); } return output.ToString(); }
public void Reboot() { using (var telnet = new TelnetConnection(Address, Port)) { NshLogin(telnet); string output = telnet.Read(); Logger.Log("Sending reboot"); telnet.WriteLine("reboot"); telnet.WriteLine(""); try { telnet.Read(); //must read in order for command to actually be executed } catch { //just in case modem decides to reboot early } } }
public bool OpenSession(String host, String username, String password) { try { // New connection tc = new TelnetConnection(host, 23); // Login var usernamePrompt = tc.Read(2000); if (usernamePrompt.Contains("login:"******"Password:"******"admin @ home")) { _host = host; _username = username; _password = password; return true; } return false; } catch (Exception e) { return false; } }
/// <summary> /// Inputs a blank line and waits for the prompt /// </summary> /// <param name="telnet_connection"></param> /// <param name="prompt">The expected prompt. Default '>'</param> /// <param name="sendEnter">Whether to send CR before waiting</param> /// <param name="retry_count">The max number of times that we read the session looking for the prompt</param> public static void Wait_For_Prompt(TelnetConnection telnet_connection, string prompt = ">", bool sendEnter = true, int retry_count = 5) { telnet_connection.Read(); int n = 0; string data = ""; while (n < retry_count) { if (sendEnter) { telnet_connection.WriteLine(""); Thread.Sleep(250); } data = telnet_connection.Read(); if (data.Contains(prompt)) { break; } else if (telnet_connection.Port != TCLI.ISA3_ADMIN_PORT_NUM) { try { ResetISAANode(telnet_connection.HostName); } catch (Exception ex) { string msg = ex.Message; } } n++; } if (n >= retry_count) { throw new Exception("Telnet session prompt not detected"); } }
static void Main(string[] args) { Arguments cmdLine_args = new Arguments(args); if (cmdLine_args["board"] != null) { Console.WriteLine("Board set to '{0}'", cmdLine_args["board"]); } BoardTypes board_type = BoardTypes.humpback; double voltage_low_limit = 0.0; double voltage_reference = 0.0; double current_reference = 0.0; string cmd_prefix; switch (board_type) { case BoardTypes.humpback: voltage_low_limit = 200; voltage_reference = 240; current_reference = 15; cmd_prefix = "cs5490"; break; case BoardTypes.zebrashark: voltage_low_limit = 80; voltage_reference = 120; current_reference = 15; cmd_prefix = "cs5480"; break; default: cmd_prefix = "cs5490"; voltage_low_limit = 80; voltage_reference = 120; current_reference = 15; break; } //create a new telnet connection TelnetConnection tc = new TelnetConnection("localhost", 4900); string datain = tc.Read(); string msg = patch(board_type, 0x400000, 0x400000); Thread.Sleep(2000); datain = tc.Read(); tc.WriteLine("version"); Thread.Sleep(500); datain = tc.Read(); updateOutputStatus(datain); tc.WriteLine(string.Format("cu {0}_pinfo", cmd_prefix)); Thread.Sleep(500); datain = tc.Read(); updateOutputStatus(datain); string rawCurrentPattern = "Raw IRMS: ([0-9,A-F]{8})"; string rawVoltagePattern = "Raw VRMS: ([0-9,A-F]{8})"; double current_cs = 0.0; double voltage_cs = 0.0; int i = 0; int fail_count = 0; while (true) { //tc.WriteLine("cu cs5480_start_conv"); //tc.WriteLine("cu cs5480_start_single_conv"); //Thread.Sleep(1000); tc.WriteLine(string.Format("cu {0}_pload", cmd_prefix)); Thread.Sleep(500); datain = tc.Read(); updateOutputStatus(datain); if (datain.Length > 0) { Match on_off_match = Regex.Match(datain, "Changing OnOff .*"); if (on_off_match.Success) { msg = on_off_match.Value; updateOutputStatus(msg); } Match match = Regex.Match(datain, rawCurrentPattern); if (match.Groups.Count > 1) { string current_hexstr = match.Groups[1].Value; int current_int = Convert.ToInt32(current_hexstr, 16); current_cs = RegHex_ToDouble(current_int); current_cs = current_cs * current_reference / 0.6; voltage_cs = 0.0; match = Regex.Match(datain, rawVoltagePattern); if (match.Groups.Count > 1) { string voltage_hexstr = match.Groups[1].Value; int volatge_int = Convert.ToInt32(voltage_hexstr, 16); voltage_cs = RegHex_ToDouble(volatge_int); voltage_cs = voltage_cs * voltage_reference / 0.6; } if (voltage_cs > voltage_low_limit) { i++; msg = string.Format("Cirrus I = {0:F8}, V = {1:F8}, P = {2:F8}", current_cs, voltage_cs, current_cs * voltage_cs); updateOutputStatus(msg); } else { fail_count++; } if (i > 1) break; } } Thread.Sleep(1000); } /// The meter measurements MultiMeter meter = new MultiMeter("COM1"); meter.OpenComPort(); meter.SetToRemote(); meter.SetupForIAC(); string current_meter_str = meter.Measure(); current_meter_str = meter.Measure(); double current_meter = Double.Parse(current_meter_str); meter.SetupForVAC(); string voltage_meter_str = meter.Measure(); voltage_meter_str = meter.Measure(); double voltage_meter = Double.Parse(voltage_meter_str); meter.CloseSerialPort(); msg = string.Format("Meter I = {0:F8}, V = {1:F8}, P = {2:F8}", current_meter, voltage_meter, current_meter * voltage_meter); updateOutputStatus(msg); // Gain calucalation double current_gain = current_meter / current_cs; //double current_gain = current_meter / current_cs; int current_gain_int = (int)(current_gain * 0x400000); msg = string.Format("Current Gain = {0:F8} (0x{1:X})", current_gain, current_gain_int); updateOutputStatus(msg); double voltage_gain = voltage_meter / voltage_cs; int voltage_gain_int = (int)(voltage_gain * 0x400000); msg = string.Format("Voltage Gain = {0:F8} (0x{1:X})", voltage_gain, voltage_gain_int); updateOutputStatus(msg); msg = patch(board_type, voltage_gain_int, current_gain_int); Thread.Sleep(2000); datain = tc.Read(); updateOutputStatus(datain); tc.WriteLine(string.Format("cu {0}_pinfo", cmd_prefix)); Thread.Sleep(500); datain = tc.Read(); updateOutputStatus(datain); i = 0; while (true) { tc.WriteLine(string.Format("cu {0}_pload", cmd_prefix)); Thread.Sleep(500); datain = tc.Read(); Debug.WriteLine(datain); if (datain.Length > 0) { Match on_off_match = Regex.Match(datain, "Changing OnOff .*"); if (on_off_match.Success) { msg = on_off_match.Value; updateOutputStatus(msg); } Match match = Regex.Match(datain, rawCurrentPattern); if (match.Groups.Count > 1) { string current_hexstr = match.Groups[1].Value; int current_int = Convert.ToInt32(current_hexstr, 16); current_cs = RegHex_ToDouble(current_int); current_cs = current_cs * current_reference / 0.6; voltage_cs = 0.0; match = Regex.Match(datain, rawVoltagePattern); if (match.Groups.Count > 1) { string voltage_hexstr = match.Groups[1].Value; int volatge_int = Convert.ToInt32(voltage_hexstr, 16); voltage_cs = RegHex_ToDouble(volatge_int); voltage_cs = voltage_cs * voltage_reference / 0.6; } if (voltage_cs > voltage_low_limit) { i++; msg = string.Format("Cirrus I = {0:F8}, V = {1:F8}, P = {2:F8}", current_cs, voltage_cs, current_cs * voltage_cs); updateOutputStatus(msg); } if (i > 1) break; } } Thread.Sleep(1000); } tc.Close(); }
public void FactoryReset() { using (var telnet = new TelnetConnection(Address, Port)) { NshLogin(telnet); string output = telnet.Read(); Logger.Log("Sending defaults"); telnet.WriteLine("defaults"); output = telnet.Read(1000); Assert(output.Contains("the factory defaults"), "Factory Reset request did not appear to succeed"); Logger.Log("Factory Reset done. The device may take a minute to reset completely and come back online"); } }
public bool OpenSession(String host, String username, String password) { try { // New connection tc = new TelnetConnection(host, 23); // Login var passwordPrompt = tc.Read(200); if (passwordPrompt.Contains("password:")) { tc.WriteLine(password); } else { return false; } return true; } catch(Exception e) { return false; } }
public void FixRedirect() { using (var telnet = new TelnetConnection(Address, Port)) { NshLogin(telnet); string output = telnet.Read(); Logger.Log("Sending set mgmt.lan-redirect.enable off"); telnet.WriteLine("set mgmt.lan-redirect.enable off"); SaveChanges(telnet); } }
public void UninstallBackdoor() { using (var telnet = new TelnetConnection(Address, Port)) { NshLogin(telnet); string output = telnet.Read(); telnet.WriteLine("!"); telnet.WriteLine(""); telnet.WriteLine("pfs -r /var/etc/inetd.d/telnet28"); telnet.WriteLine("sleep 5"); telnet.WriteLine("pfs -s"); // telnet.WriteLine("pfs -l"); telnet.WriteLine("exit"); Logger.Log(telnet.Read()); //must read in order for command to actually be executed } }
private bool Connect() { ambiBoxConnection = new TelnetConnection(coreObject.ambiBoxIP, coreObject.ambiBoxPort); if (ambiBoxConnection == null || !ambiBoxConnection.IsConnected) { return false; } ambiBoxConnection.Read(); char[] separators = { ':', ';' }; string profilesString = SendCommand("getprofiles", true); if (string.IsNullOrEmpty(profilesString)) { return false; } string[] profiles = profilesString.Split(separators); for (int i = 1; i < profiles.Length; i++) { if (!string.IsNullOrEmpty(profiles[i])) { profileList.Add(profiles[i]); } } currentProfile = SendCommand("getprofile", true).Split(separators)[1]; ledCount = int.Parse(SendCommand("getcountleds", true).Split(separators)[1]); if (ledCount <= 0) { return false; } SendCommand("unlock", true); Log.Info("AmbiBoxHandler - Successfully connected to {0}:{1}", coreObject.ambiBoxIP, coreObject.ambiBoxPort); return true; }
/// <summary> /// Gets the MFG string /// </summary> /// <param name="telnet_connection"></param> /// <returns></returns> public static string Get_MFGString(TelnetConnection telnet_connection) { string mfgstr = null; string datain = ""; string pattern = "MFG String: (\\S+)"; TCLI.Wait_For_Prompt(telnet_connection); telnet_connection.WriteLine("info"); Thread.Sleep(500); datain = telnet_connection.Read(); if (datain != null && datain.Length > 0) { Match match = Regex.Match(datain, pattern); if (match.Groups.Count != 2) { string msg = string.Format("Unable to parse info MFG String. Output was:{0}", datain); throw new Exception(msg); } mfgstr = match.Groups[1].Value; } else { string msg = string.Format("No data received after \"Info\" command"); throw new Exception(msg); } return mfgstr; }
public void DisableUpnp() { using (var telnet = new TelnetConnection(Address, Port)) { NshLogin(telnet); string output = telnet.Read(); telnet.WriteLine("set mgmt.upnp.enable off"); SaveChanges(telnet); } }