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) { 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"); }
public Calibrate(BoardTypes boardtype, RelayControler relay_controller, TelnetConnection telnet_connection, MultiMeter meter) { BoardType = boardtype; _relay_ctrl = relay_controller; _telnet_connection = telnet_connection; _meter = meter; }
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); } }
/// <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 Form_PowerMeter(TelnetConnection telnet_connection) { InitializeComponent(); this.Icon = Properties.Resources.Icon_PowerCalibration; _telnet_connection = telnet_connection; this.CLIValue_Event += Form_PowerMeter_CLIValue_Event; this.CLIError_Event += Form_PowerMeter_CLIError_Event; setErrorVisibility(false); }
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); } }
public void Connect(ToolStripStatusLabel toolStatus, ToolStripProgressBar toolProgress) { TelnetConnection tc = new TelnetConnection(settings.Address, 23); string s = tc.Login(settings.Username, settings.Password, 100); Console.Write(s); tc.WriteLine("/etc/enigma2/AutoRecorder/reconf /etc/enigma2/AutoRecorder/SearchProfiles/Automaatti.prof >/etc/enigma2/AutoRecorder/SearchProfiles/AutomaattiOut.py"); ftp ftpClient = new ftp(@"ftp://" + settings.Address, settings.Username, settings.Password); toolProgress.Value = 65; toolStatus.Text = "Downloading..."; ftpClient.download("/etc/enigma2/AutoRecorder/SearchProfiles/AutomaattiOut.py", @".\AutomaattiOut.py"); }
static void Main(string[] args) { try { //Создает Telnet-соединение по IP:Port TelnetConnection tc = new TelnetConnection("46.172.182.72", 23); //Указываем логин, пароль и время ожидания string s = tc.Login(" ", " ", 100); // Строка ответа должна заканчиватсья на "$" или ">", иначе соединение неудачно string prompt = s.TrimEnd(); prompt = s.Substring(prompt.Length - 1, 1); if (prompt != "$" && prompt != ">") { throw new Exception("Connection failed"); } Console.WriteLine("OMG! TelNet Connection is success! U can do everything! Hahahaha: "); prompt = ""; // Цикл обработки while (tc.IsConnected && prompt.Trim() != "exit") { // Вывод ответа сервера Console.Write(tc.Read()); // Отправляем серверу команду prompt = Console.ReadLine(); tc.WriteLine(prompt); // Вывод ответа сервера Console.Write(tc.Read()); } Console.WriteLine("Disconnected"); Console.ReadLine(); } catch (Exception exception) { Console.WriteLine(exception.ToString()); } finally { Console.ReadKey(); } }
/// <summary> /// Establish a Telnet connection with the router /// </summary> public RouterCnx(string aIPAddress, string aLogin, string aPassword) { IPAdress = aIPAddress; Login = aLogin; Password = aPassword; TelnetCnx = new TelnetConnection(IPAdress, 23); string Response = TelnetCnx.Login(Login, Password, 300); string prompt = Response.TrimEnd(); prompt = Response.Substring(prompt.Length - 1, 1); if (prompt != "$" && prompt != ">" && prompt != "#") { throw new Exception("Unable to connect to the requested IP"); } }
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()); }
public void UploadConfig(ToolStripStatusLabel toolStatus, ToolStripProgressBar toolProgress) { TelnetConnection tc = new TelnetConnection(settings.Address, 23); string s = tc.Login(settings.Username, settings.Password, 100); Console.Write(s); tc.WriteLine("mv /etc/enigma2/AutoRecorder/SearchProfiles/Automaatti.py /etc/enigma2/AutoRecorder/SearchProfiles/Automaatti-2.py"); ftp ftpClient = new ftp(@"ftp://" + settings.Address, settings.Username, settings.Password); Thread.Sleep(1000); toolProgress.Value = 65; toolStatus.Text = "Uploading..."; //ftpClient.upload(@".\AutomaattiIn.py", "/etc/enigma2/AutoRecorder/SearchProfiles/Automaatti.py"); ftpClient.upload("/etc/enigma2/AutoRecorder/SearchProfiles/Automaatti.py", "AutomaattiIn.py"); tc.WriteLine("cd /etc/enigma2/AutoRecorder/SearchProfiles"); tc.WriteLine("chmod 777 Automaatti.py"); tc.WriteLine("./Automaatti.py"); toolProgress.Value = 0; toolStatus.Text = "Ready"; }
/// <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; }
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; }
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; }
private void Form1_Load(object sender, EventArgs e) { _tc = new TelnetConnection("telehack.com", 23); }
/// <summary> /// The main re-coding function /// Reads the calibration tokens, codes and reprograms the same tokens /// </summary> /// <param name="cancel"></param> public void Run(CancellationToken cancel) { // Check to see if Ember is to be used as USB and open ISA channel if so // Also set the box address Ember.Interfaces ember_interface = (Ember.Interfaces)Enum.Parse( typeof(Ember.Interfaces), Properties.Settings.Default.Ember_Interface); _ember.Interface = ember_interface; if (_ember.Interface == Ember.Interfaces.USB) { _ember.Interface_Address = Properties.Settings.Default.Ember_Interface_USB_Address; fire_run_status("Open ISA Channels"); _ember.OpenISAChannels(); } else { _ember.Interface_Address = Properties.Settings.Default.Ember_Interface_IP_Address; } TCLI.Tokens caltokens = new TCLI.Tokens(eui: "", ifactor: 0, vfactor: 0, igain: 0, vgain: 0); string msg = ""; bool got_tokens = false; string log_file = ""; string eui = ""; while (true) { if (cancel.IsCancellationRequested) break; try { // Create a new telnet connection fire_run_status("Start telnet"); // If interface is USB we use localhost string telnet_address = "localhost"; if (_ember.Interface == Ember.Interfaces.IP) telnet_address = _ember.Interface_Address; _telnet_connection = new TelnetConnection(telnet_address, 4900); fire_run_status("Get EUI"); eui = TCLI.Get_EUI(_telnet_connection); //DialogResult rc = ShowInputDialog(ref serial_number, inputbox_label: "Serial"); //if (rc == DialogResult.Cancel) // throw new Exception("Serial number not entered"); fire_status("EUI = " + eui); fire_run_status("Get UUT Tokens"); string cmd_prefix = TCLI.Get_Custom_Command_Prefix(_telnet_connection); caltokens = TCLI.Parse_Pinfo_Tokens(_telnet_connection, cmd_prefix); caltokens.EUI = eui; msg = string.Format("Voltage Factor: {0}, ", caltokens.VoltageFactor); msg += string.Format("Current Factor: {0}, ", caltokens.CurrentFactor); msg += string.Format("VGain Token: 0x{0:X08}, ", caltokens.VoltageGainToken); msg += string.Format("CGain Token: 0x{0:X08}", caltokens.CurrentGainToken); fire_status(msg); string filename = string.Format("tokens_{0}-{1:yyyy-MM-dd_hh-mm-ss-tt}.txt", eui, DateTime.Now); log_file = Path.Combine(_app_data_dir, filename); // Path to the app log file msg = string.Format("::EUI: {0}\r\n::{1}\r\n", eui, msg); File.WriteAllText(log_file, msg); got_tokens = true; break; } catch (Exception ex) { string retry_err_msg = ex.Message; int max_len = 1000; if (retry_err_msg.Length > max_len) retry_err_msg = retry_err_msg.Substring(0, max_len) + "..."; DialogResult dlg_rc = MessageBox.Show(retry_err_msg, "Exception reading tokens", MessageBoxButtons.RetryCancel); if (dlg_rc == System.Windows.Forms.DialogResult.Cancel) throw; } finally { _telnet_connection.Close(); _ember.CloseISAChannels(); } } if (!got_tokens) { throw new Exception("Tokens not read"); } try { // Code here fire_run_status("Code"); Coder coder = new Coder(new TimeSpan(0, 2, 0)); coder.Code(cancel); } catch (Exception) { throw; } finally { // Repatch the tokens fire_run_status("Patch UUT Tokens"); //caltokens.VoltageGainToken = 0x00405E00; //caltokens.CurrentGainToken = 0X002F7EB7; //caltokens.VoltageFactor = 240; //caltokens.CurrentFactor = 15; _ember.VoltageRefereceValue = caltokens.VoltageFactor; _ember.CurrentRefereceValue = caltokens.CurrentFactor; string cmd_str = _ember.CreateCalibrationPatchBath(vgain: caltokens.VoltageGainToken, igain: caltokens.CurrentGainToken); if (File.Exists(log_file)) { File.AppendAllText(log_file, cmd_str); } while (true) { string[] ember_temp_files = Ember.CleanupTempPatchFile(); foreach (string file in ember_temp_files) fire_status(string.Format("Ember temp file found and removed {0}", file)); try { string patch_output = _ember.RunCalibrationPatchBatch(); break; } catch (Exception ex) { string retry_err_msg = ex.Message; int max_len = 1000; if (retry_err_msg.Length > max_len) retry_err_msg = retry_err_msg.Substring(0, max_len) + "..."; DialogResult dlg_rc = MessageBox.Show(retry_err_msg, "Exception patching tokens", MessageBoxButtons.RetryCancel); if (dlg_rc == System.Windows.Forms.DialogResult.Cancel) throw; } } } }
/// <summary> /// Creates telnet session using app settings /// </summary> TelnetConnection createTelnet() { // Check to see if Ember is to be used as USB and open ISA channel if so // Also set the box address Ember.Interfaces ember_interface = (Ember.Interfaces)Enum.Parse( typeof(Ember.Interfaces), Properties.Settings.Default.Ember_Interface); _ember.Interface = ember_interface; if (_ember.Interface == Ember.Interfaces.USB) { _ember.Interface_Address = Properties.Settings.Default.Ember_Interface_USB_Address; TraceLogger.Log("Start Ember isachan"); _ember.OpenISAChannels(); } else { _ember.Interface_Address = Properties.Settings.Default.Ember_Interface_IP_Address; } // Create a new telnet connection TraceLogger.Log("Start telnet"); // If interface is USB we use localhost string telnet_address = "localhost"; if (_ember.Interface == Ember.Interfaces.IP) telnet_address = _ember.Interface_Address; _telnet_connection = new TelnetConnection(telnet_address, 4900); return _telnet_connection; }
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(); }
/// <summary> /// Closes the board relay using custom command /// </summary> /// <param name="board_type"></param> /// <param name="telnet_connection"></param> void set_board_relay(BoardTypes board_type, TelnetConnection telnet_connection, bool value) { switch (board_type) { // These boards have relays case BoardTypes.Hooktooth: case BoardTypes.Hornshark: case BoardTypes.Humpback: case BoardTypes.Zebrashark: updateRunStatus(string.Format("Set UUT Relay {0}", value.ToString())); if (value) telnet_connection.WriteLine("write 1 6 0 1 0x10 {01}"); else telnet_connection.WriteLine("write 1 6 0 1 0x10 {00}"); break; } }
/// <summary> /// Closes telnet and ISA channels /// </summary> void closeTelnet() { if (_telnet_connection != null) { TraceLogger.Log("Close telnet"); _telnet_connection.Close(); _telnet_connection = null; } if (_ember != null && _ember.Interface == Ember.Interfaces.USB) { _ember.CloseISAChannels(); } }
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; } }
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 bool GetPCMStatus(int bsc, int pcm) { //string line; string bscMap; BscMap aMap=new BscMap(); bool pcmUP = false; bool connected; System.IO.StreamReader ipMap=new StreamReader(@"D:\input\ip_map.csv"); while ((bscMap = ipMap.ReadLine()) != null) { if (bscMap.Contains(bsc.ToString())) { string[] map=bscMap.Split(','); aMap.Name = map[1]; aMap.IPaddress = map[2]; aMap.BSCuser = map[3]; aMap.BSCpass = map[4]; } } try { TelnetConnection aTelnetConnection = new TelnetConnection(aMap.IPaddress, 23); aTelnetConnection.Login(aMap.BSCuser, aMap.BSCpass, 100, out connected); string output = aTelnetConnection.ExecuteCommand("ZDTI:::PCM=" + pcm + ";"); if (output.Contains("WO-EX")) { pcmUP = true; //break; } } catch { pcmUP = false;} //string[] outputArray = output.Split('\n'); //foreach (string s in outputArray) //{ // if (s.Contains("NETW")) // { // s.Remove('"'); // s.Remove(' '); // // string[] aLAPD = s.Split(); // if (s.Contains("WO-EX")) // { // pcmUP = true; // break; // } // } //} //System.IO.StreamReader file = // new System.IO.StreamReader(output); //while ((line = file.ReadLine()) != null) //{ // if (line.Contains("NETW")) // { // string [] aLAPD=line.Split(); // if (aLAPD[6] == "WO") // { // pcmUP = true; // break; // } // } //} return pcmUP; }
private void Disconnect() { if (ambiBoxConnection != null) { ambiBoxConnection.Dispose(); ambiBoxConnection = null; } }
public List<BCSU> GetLogicalBCSU(List<string> bscList ) { System.IO.StreamReader ipMap = new StreamReader(@"D:\input\ip_map.csv"); BscMap aMap = new BscMap(); string bscMap; bool connected; foreach (string bsc in bscList) { while ((bscMap = ipMap.ReadLine()) != null) { if (bscMap.Contains(bsc)) { string[] map = bscMap.Split(','); aMap.Name = map[1]; aMap.IPaddress = map[2]; aMap.BSCuser = map[3]; aMap.BSCpass = map[4]; } } try { TelnetConnection aTelnetConnection = new TelnetConnection(aMap.IPaddress, 23); aTelnetConnection.Login(aMap.BSCuser, aMap.BSCpass, 100, out connected); aTelnetConnection.ExecuteCommand("ZDDS;"); string logBCSU = aTelnetConnection.ExecuteCommand("ZLE:U,RCBUGGGX"); logBCSU += aTelnetConnection.ExecuteCommand("U"); logBCSU += aTelnetConnection.ExecuteCommand("ZUSI:BCSU"); logBCSU += aTelnetConnection.ExecuteCommand("Z"); logBCSU += aTelnetConnection.ExecuteCommand("Z"); logBCSU += aTelnetConnection.ExecuteCommand("ZE"); } catch { connected = false; } } return null; }
public void EnableBackdoorIfNeeded() { Logger.Log("Checking for backdoor installation on port 28"); try { using(var t = new TelnetConnection(Address, 28)); Logger.Log("Backdoor is already installed at port 28!"); return; } catch { Logger.Log("Backdoor does not appear to be installed! Proceeding with installation"); } EnableBackdoor(true); Logger.Log("Waiting 2 minutes for modem to reboot"); Thread.Sleep(60 * 2000); try { using(var t = new TelnetConnection(Address, 28)); } catch(Exception e) { Logger.Log("Backdoor installation did not appear to work! :( Nothing more can be done"); throw; } Logger.Log("Backdoor installation accessible at port 28 is successful!"); }
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; } }
private void Disconnect() { if (boblightConnection != null) { boblightConnection.Dispose(); boblightConnection = null; } }
private bool Connect() { try { lights.Clear(); boblightConnection = new TelnetConnection(coreObject.boblightIP, coreObject.boblightPort); if (boblightConnection.IsConnected) { if (SendCommand("hello\n", true) != "hello") { return false; } string lightsMessage = SendCommand("get lights", true); if (string.IsNullOrEmpty(lightsMessage)) { return false; } string[] lightsArray = lightsMessage.Split(' ', '\n'); for (int i = 0; i < lightsArray.Length; i++) { if (lightsArray[i] == "lights") { totalLights = Convert.ToInt32(lightsArray[i + 1]); i++; } else if (lightsArray[i] == "light") { lights.Add(new Light(lightsArray[i + 1], (int)Math.Round((Convert.ToDouble(lightsArray[i + 3]) / 100 * (coreObject.GetCaptureHeight() - 1))), (int)Math.Round((Convert.ToDouble(lightsArray[i + 4]) / 100 * (coreObject.GetCaptureHeight() - 1))), (int)Math.Round((Convert.ToDouble(lightsArray[i + 5]) / 100 * (coreObject.GetCaptureWidth() - 1))), (int)Math.Round((Convert.ToDouble(lightsArray[i + 6]) / 100 * (coreObject.GetCaptureWidth() - 1))))); i += 6; } } if (lights.Count != totalLights) { return false; } SetOption("speed", coreObject.boblightSpeed.ToString()); SetOption("interpolation", Convert.ToInt32(coreObject.boblightInterpolation).ToString()); return true; } else { return false; } } catch (Exception ex) { Log.Error("BoblightHandler - Error during connecting."); Log.Error("BoblightHandler - Exception: {0}", ex.Message); return false; } }
public List<TRXInfo> GetAllPcmInStatus(List<TRXInfo> trxThisPCM, Dictionary<int, List<int>> pcmStatusDictionary) { BscMap aMap = new BscMap(); string bscMap; bool connected; List<PCMInfo> apcmList = new List<PCMInfo>(); foreach (KeyValuePair<int, List<int>> pcmInfo in pcmStatusDictionary) { System.IO.StreamReader ipMap = new StreamReader(@"D:\input\ip_map.csv"); while ((bscMap = ipMap.ReadLine()) != null) { if (bscMap.Contains(pcmInfo.Key.ToString())) { string[] map = bscMap.Split(','); aMap.Name = map[1]; aMap.IPaddress = map[2]; aMap.BSCuser = map[3]; aMap.BSCpass = map[4]; ipMap.Close(); break; } } TelnetConnection aTelnetConnection = new TelnetConnection(aMap.IPaddress, 23); aTelnetConnection.Login(aMap.BSCuser, aMap.BSCpass, 100, out connected); foreach (int eachPCM in pcmInfo.Value) { string output = aTelnetConnection.ExecuteCommand("ZDTI:::PCM=" + eachPCM + ";"); if (output.Contains("WO-EX")) { //pcmUP = true; PCMInfo aPcmInfo = new PCMInfo(); aPcmInfo.BSC = pcmInfo.Key; aPcmInfo.PCMno = eachPCM; aPcmInfo.PCmStatus = true; apcmList.Add(aPcmInfo); //break; } else { PCMInfo aPcmInfo = new PCMInfo(); aPcmInfo.BSC = pcmInfo.Key; aPcmInfo.PCMno = eachPCM; aPcmInfo.PCmStatus = false; apcmList.Add(aPcmInfo); } } aTelnetConnection.ExecuteCommand("Z;"); } foreach (TRXInfo aTrxInfo in trxThisPCM) { aTrxInfo.PCmStatus = apcmList.Where(d => d.BSC == aTrxInfo.BSC && d.PCMno == aTrxInfo.PCM).First().PCmStatus; } return trxThisPCM; }
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); } }