commit 392f73ee25788cd5b748799ef8dea54dc8b75432 Author: An Dao Date: Fri Dec 12 12:40:19 2025 -0800 Tryout GIT with Testing code diff --git a/SSH_Test/App.config b/SSH_Test/App.config new file mode 100644 index 0000000..193aecc --- /dev/null +++ b/SSH_Test/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/SSH_Test/FormConfiguration.Designer.cs b/SSH_Test/FormConfiguration.Designer.cs new file mode 100644 index 0000000..64bb98a --- /dev/null +++ b/SSH_Test/FormConfiguration.Designer.cs @@ -0,0 +1,182 @@ +namespace SSH_Test +{ + partial class FormConfiguration + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.labelIP = new System.Windows.Forms.Label(); + this.textBoxSftpIP = new System.Windows.Forms.TextBox(); + this.groupBox1 = new System.Windows.Forms.GroupBox(); + this.label2 = new System.Windows.Forms.Label(); + this.textBoxSftpPassword = new System.Windows.Forms.TextBox(); + this.label1 = new System.Windows.Forms.Label(); + this.textBoxSftpUsername = new System.Windows.Forms.TextBox(); + this.buttonOK = new System.Windows.Forms.Button(); + this.groupBox2 = new System.Windows.Forms.GroupBox(); + this.label5 = new System.Windows.Forms.Label(); + this.textBoxTftpIP = new System.Windows.Forms.TextBox(); + this.groupBox1.SuspendLayout(); + this.groupBox2.SuspendLayout(); + this.SuspendLayout(); + // + // labelIP + // + this.labelIP.AutoSize = true; + this.labelIP.Location = new System.Drawing.Point(20, 28); + this.labelIP.Name = "labelIP"; + this.labelIP.Size = new System.Drawing.Size(17, 13); + this.labelIP.TabIndex = 0; + this.labelIP.Text = "IP"; + this.labelIP.Click += new System.EventHandler(this.label1_Click); + // + // textBoxSftpIP + // + this.textBoxSftpIP.Location = new System.Drawing.Point(55, 25); + this.textBoxSftpIP.Name = "textBoxSftpIP"; + this.textBoxSftpIP.Size = new System.Drawing.Size(214, 20); + this.textBoxSftpIP.TabIndex = 1; + this.textBoxSftpIP.TextChanged += new System.EventHandler(this.textBox1_TextChanged); + // + // groupBox1 + // + this.groupBox1.Controls.Add(this.label2); + this.groupBox1.Controls.Add(this.textBoxSftpPassword); + this.groupBox1.Controls.Add(this.label1); + this.groupBox1.Controls.Add(this.textBoxSftpUsername); + this.groupBox1.Controls.Add(this.labelIP); + this.groupBox1.Controls.Add(this.textBoxSftpIP); + this.groupBox1.Location = new System.Drawing.Point(12, 71); + this.groupBox1.Name = "groupBox1"; + this.groupBox1.Size = new System.Drawing.Size(278, 118); + this.groupBox1.TabIndex = 3; + this.groupBox1.TabStop = false; + this.groupBox1.Text = "Sftp"; + this.groupBox1.Enter += new System.EventHandler(this.groupBox1_Enter); + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(20, 80); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(53, 13); + this.label2.TabIndex = 4; + this.label2.Text = "Password"; + this.label2.Click += new System.EventHandler(this.label2_Click); + // + // textBoxSftpPassword + // + this.textBoxSftpPassword.Location = new System.Drawing.Point(83, 77); + this.textBoxSftpPassword.Name = "textBoxSftpPassword"; + this.textBoxSftpPassword.Size = new System.Drawing.Size(186, 20); + this.textBoxSftpPassword.TabIndex = 5; + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(20, 54); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(57, 13); + this.label1.TabIndex = 2; + this.label1.Text = "UserName"; + // + // textBoxSftpUsername + // + this.textBoxSftpUsername.Location = new System.Drawing.Point(83, 51); + this.textBoxSftpUsername.Name = "textBoxSftpUsername"; + this.textBoxSftpUsername.Size = new System.Drawing.Size(186, 20); + this.textBoxSftpUsername.TabIndex = 3; + // + // buttonOK + // + this.buttonOK.Location = new System.Drawing.Point(55, 195); + this.buttonOK.Name = "buttonOK"; + this.buttonOK.Size = new System.Drawing.Size(151, 23); + this.buttonOK.TabIndex = 4; + this.buttonOK.Text = "OK"; + this.buttonOK.UseVisualStyleBackColor = true; + this.buttonOK.Click += new System.EventHandler(this.buttonOK_Click); + // + // groupBox2 + // + this.groupBox2.Controls.Add(this.label5); + this.groupBox2.Controls.Add(this.textBoxTftpIP); + this.groupBox2.Location = new System.Drawing.Point(12, 12); + this.groupBox2.Name = "groupBox2"; + this.groupBox2.Size = new System.Drawing.Size(278, 53); + this.groupBox2.TabIndex = 6; + this.groupBox2.TabStop = false; + this.groupBox2.Text = "Tftp"; + // + // label5 + // + this.label5.AutoSize = true; + this.label5.Location = new System.Drawing.Point(20, 28); + this.label5.Name = "label5"; + this.label5.Size = new System.Drawing.Size(17, 13); + this.label5.TabIndex = 0; + this.label5.Text = "IP"; + // + // textBoxTftpIP + // + this.textBoxTftpIP.Location = new System.Drawing.Point(55, 25); + this.textBoxTftpIP.Name = "textBoxTftpIP"; + this.textBoxTftpIP.Size = new System.Drawing.Size(214, 20); + this.textBoxTftpIP.TabIndex = 1; + // + // FormConfiguration + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(297, 228); + this.Controls.Add(this.groupBox2); + this.Controls.Add(this.buttonOK); + this.Controls.Add(this.groupBox1); + this.Name = "FormConfiguration"; + this.Text = "FormConfiguration"; + this.groupBox1.ResumeLayout(false); + this.groupBox1.PerformLayout(); + this.groupBox2.ResumeLayout(false); + this.groupBox2.PerformLayout(); + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.Label labelIP; + private System.Windows.Forms.TextBox textBoxSftpIP; + private System.Windows.Forms.GroupBox groupBox1; + private System.Windows.Forms.Label label2; + private System.Windows.Forms.TextBox textBoxSftpPassword; + private System.Windows.Forms.Label label1; + private System.Windows.Forms.TextBox textBoxSftpUsername; + private System.Windows.Forms.Button buttonOK; + private System.Windows.Forms.GroupBox groupBox2; + private System.Windows.Forms.Label label5; + private System.Windows.Forms.TextBox textBoxTftpIP; + } +} \ No newline at end of file diff --git a/SSH_Test/FormConfiguration.cs b/SSH_Test/FormConfiguration.cs new file mode 100644 index 0000000..5a2e20c --- /dev/null +++ b/SSH_Test/FormConfiguration.cs @@ -0,0 +1,59 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace SSH_Test +{ + public partial class FormConfiguration : Form + { + public string Tftp_IP { get; set; } + public string Sftp_IP { get; set; } + public string Sftp_Username { get; set; } + public string Sftp_Password { get; set; } + + public FormConfiguration(string tftp_IP, string sftpIP, string sftp_Username, string sftp_Password) + { + InitializeComponent(); + this.textBoxTftpIP.Text = Tftp_IP = tftp_IP; + this.textBoxSftpIP.Text = Sftp_IP = sftpIP; + this.textBoxSftpUsername.Text = Sftp_Username = sftp_Username; + this.textBoxSftpPassword.Text = Sftp_Password = sftp_Password; + this.Update(); + } + + private void groupBox1_Enter(object sender, EventArgs e) + { + + } + + private void textBox1_TextChanged(object sender, EventArgs e) + { + + } + + private void label1_Click(object sender, EventArgs e) + { + + } + + private void label2_Click(object sender, EventArgs e) + { + + } + + private void buttonOK_Click(object sender, EventArgs e) + { + Tftp_IP = textBoxTftpIP.Text; + Sftp_IP = textBoxSftpIP.Text; + Sftp_Username = textBoxSftpUsername.Text; + Sftp_Password = textBoxSftpPassword.Text; + this.Close(); + } + } +} diff --git a/SSH_Test/FormConfiguration.resx b/SSH_Test/FormConfiguration.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/SSH_Test/FormConfiguration.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/SSH_Test/FormCredential.Designer.cs b/SSH_Test/FormCredential.Designer.cs new file mode 100644 index 0000000..e8fc6b7 --- /dev/null +++ b/SSH_Test/FormCredential.Designer.cs @@ -0,0 +1,124 @@ +namespace SSH_Test +{ + partial class FormCredential + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.textBoxUserName = new System.Windows.Forms.TextBox(); + this.textBoxPassword = new System.Windows.Forms.TextBox(); + this.label1 = new System.Windows.Forms.Label(); + this.label2 = new System.Windows.Forms.Label(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.buttonOK = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // textBoxUserName + // + this.textBoxUserName.Location = new System.Drawing.Point(12, 25); + this.textBoxUserName.Name = "textBoxUserName"; + this.textBoxUserName.Size = new System.Drawing.Size(176, 20); + this.textBoxUserName.TabIndex = 0; + this.textBoxUserName.WordWrap = false; + this.textBoxUserName.TextChanged += new System.EventHandler(this.textBoxUserName_TextChanged); + // + // textBoxPassword + // + this.textBoxPassword.Location = new System.Drawing.Point(12, 64); + this.textBoxPassword.Name = "textBoxPassword"; + this.textBoxPassword.PasswordChar = '*'; + this.textBoxPassword.Size = new System.Drawing.Size(176, 20); + this.textBoxPassword.TabIndex = 1; + this.textBoxPassword.TextChanged += new System.EventHandler(this.textBoxPassword_TextChanged); + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(12, 9); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(63, 13); + this.label1.TabIndex = 2; + this.label1.Text = "User Name:"; + this.label1.Click += new System.EventHandler(this.label1_Click); + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(12, 48); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(53, 13); + this.label2.TabIndex = 3; + this.label2.Text = "Password"; + this.label2.Click += new System.EventHandler(this.label2_Click); + // + // buttonCancel + // + this.buttonCancel.Location = new System.Drawing.Point(12, 90); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(75, 23); + this.buttonCancel.TabIndex = 4; + this.buttonCancel.Text = "Cancel"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.buttonCancel_Click); + // + // buttonOK + // + this.buttonOK.Location = new System.Drawing.Point(111, 90); + this.buttonOK.Name = "buttonOK"; + this.buttonOK.Size = new System.Drawing.Size(75, 23); + this.buttonOK.TabIndex = 5; + this.buttonOK.Text = "OK"; + this.buttonOK.UseVisualStyleBackColor = true; + this.buttonOK.Click += new System.EventHandler(this.buttonOK_Click); + // + // FormCredential + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(198, 119); + this.Controls.Add(this.buttonOK); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.label2); + this.Controls.Add(this.label1); + this.Controls.Add(this.textBoxPassword); + this.Controls.Add(this.textBoxUserName); + this.Name = "FormCredential"; + this.Text = "Credential"; + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.TextBox textBoxUserName; + private System.Windows.Forms.TextBox textBoxPassword; + private System.Windows.Forms.Label label1; + private System.Windows.Forms.Label label2; + private System.Windows.Forms.Button buttonCancel; + private System.Windows.Forms.Button buttonOK; + } +} \ No newline at end of file diff --git a/SSH_Test/FormCredential.cs b/SSH_Test/FormCredential.cs new file mode 100644 index 0000000..817afbd --- /dev/null +++ b/SSH_Test/FormCredential.cs @@ -0,0 +1,62 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace SSH_Test +{ + public partial class FormCredential : Form + { + public string Username { get; set; } + public string Password { get; set; } + public FormCredential(string username, string password) + { + + InitializeComponent(); + textBoxUserName.Text = Username=username; + textBoxUserName.Update(); + textBoxPassword.Text = Password=password; + textBoxPassword.Update(); + } + + private void label1_Click(object sender, EventArgs e) + { + + } + + private void label2_Click(object sender, EventArgs e) + { + + } + + private void textBoxUserName_TextChanged(object sender, EventArgs e) + { + textBoxUserName.Focus(); + Username = textBoxUserName.Text; + + } + + private void textBoxPassword_TextChanged(object sender, EventArgs e) + { + textBoxPassword.Focus(); + Password = textBoxPassword.Text; + } + + private void buttonCancel_Click(object sender, EventArgs e) + { + Username = ""; + Password = ""; + this.Close(); + } + + private void buttonOK_Click(object sender, EventArgs e) + { + this.Close(); + } + } +} diff --git a/SSH_Test/FormCredential.resx b/SSH_Test/FormCredential.resx new file mode 100644 index 0000000..61bc649 --- /dev/null +++ b/SSH_Test/FormCredential.resx @@ -0,0 +1,123 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + True + + \ No newline at end of file diff --git a/SSH_Test/FormProfile.Designer.cs b/SSH_Test/FormProfile.Designer.cs new file mode 100644 index 0000000..ac1ccb3 --- /dev/null +++ b/SSH_Test/FormProfile.Designer.cs @@ -0,0 +1,80 @@ +namespace SSH_Test +{ + partial class FormProfile + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.comboBoxProfile = new System.Windows.Forms.ComboBox(); + this.bOK = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // comboBoxProfile + // + this.comboBoxProfile.FormattingEnabled = true; + this.comboBoxProfile.Items.AddRange(new object[] { + "Cisco_Switch", + "Cisco_Switch_Tftp", + "Cisco_Switch_Sftp", + "Cisco_Switch_Tftp_Startup", + "Cisco_Router", + "Cisco-Firewall"}); + this.comboBoxProfile.Location = new System.Drawing.Point(12, 12); + this.comboBoxProfile.Name = "comboBoxProfile"; + this.comboBoxProfile.Size = new System.Drawing.Size(121, 21); + this.comboBoxProfile.TabIndex = 0; + this.comboBoxProfile.TextChanged += new System.EventHandler(this.comboBoxProfile_TextChanged); + // + // bOK + // + this.bOK.Location = new System.Drawing.Point(13, 56); + this.bOK.Name = "bOK"; + this.bOK.Size = new System.Drawing.Size(120, 23); + this.bOK.TabIndex = 1; + this.bOK.Text = "OK"; + this.bOK.UseCompatibleTextRendering = true; + this.bOK.UseVisualStyleBackColor = true; + this.bOK.Click += new System.EventHandler(this.bOK_Click); + // + // FormProfile + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(144, 98); + this.Controls.Add(this.bOK); + this.Controls.Add(this.comboBoxProfile); + this.Name = "FormProfile"; + this.Text = "Profile"; + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.ComboBox comboBoxProfile; + private System.Windows.Forms.Button bOK; + } +} \ No newline at end of file diff --git a/SSH_Test/FormProfile.cs b/SSH_Test/FormProfile.cs new file mode 100644 index 0000000..f5addab --- /dev/null +++ b/SSH_Test/FormProfile.cs @@ -0,0 +1,48 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using static System.Windows.Forms.VisualStyles.VisualStyleElement; + +namespace SSH_Test +{ + public partial class FormProfile : Form + { + public string sProfile { get; set; } + public FormProfile(string sProfile) + { + InitializeComponent(); + this.sProfile = sProfile; + if (sProfile != null) sProfile = "Cisco_Switch"; + + int index = comboBoxProfile.FindStringExact(sProfile); + + // If the item is found, set it as the selected item + if (index != -1) + { + comboBoxProfile.SelectedIndex = index; + } + else + { + + comboBoxProfile.SelectedIndex = 0; + } + } + + private void bOK_Click(object sender, EventArgs e) + { + this.Close(); + } + + private void comboBoxProfile_TextChanged(object sender, EventArgs e) + { + Console.WriteLine("Profile changes to: {0}", comboBoxProfile.SelectedItem.ToString()); + sProfile = comboBoxProfile.SelectedItem.ToString(); + } + } +} diff --git a/SSH_Test/FormProfile.resx b/SSH_Test/FormProfile.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/SSH_Test/FormProfile.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/SSH_Test/Program.cs b/SSH_Test/Program.cs new file mode 100644 index 0000000..733f96c --- /dev/null +++ b/SSH_Test/Program.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace SSH_Test +{ + internal static class Program + { + /// + /// The main entry point for the application. + /// + [STAThread] + static void Main() + { + Application.EnableVisualStyles(); + Application.SetCompatibleTextRenderingDefault(false); + Application.Run(new TastList()); + } + } +} diff --git a/SSH_Test/Properties/AssemblyInfo.cs b/SSH_Test/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..f67bace --- /dev/null +++ b/SSH_Test/Properties/AssemblyInfo.cs @@ -0,0 +1,33 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("SSH_Test")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("SSH_Test")] +[assembly: AssemblyCopyright("Copyright © 2025")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("73ded4cd-b2b1-491e-87b7-bc1f11759c53")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/SSH_Test/Properties/Resources.Designer.cs b/SSH_Test/Properties/Resources.Designer.cs new file mode 100644 index 0000000..1af5ec4 --- /dev/null +++ b/SSH_Test/Properties/Resources.Designer.cs @@ -0,0 +1,71 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace SSH_Test.Properties +{ + + + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources + { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() + { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager + { + get + { + if ((resourceMan == null)) + { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("SSH_Test.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture + { + get + { + return resourceCulture; + } + set + { + resourceCulture = value; + } + } + } +} diff --git a/SSH_Test/Properties/Resources.resx b/SSH_Test/Properties/Resources.resx new file mode 100644 index 0000000..af7dbeb --- /dev/null +++ b/SSH_Test/Properties/Resources.resx @@ -0,0 +1,117 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/SSH_Test/Properties/Settings.Designer.cs b/SSH_Test/Properties/Settings.Designer.cs new file mode 100644 index 0000000..ae6ef31 --- /dev/null +++ b/SSH_Test/Properties/Settings.Designer.cs @@ -0,0 +1,30 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace SSH_Test.Properties +{ + + + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")] + internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase + { + + private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); + + public static Settings Default + { + get + { + return defaultInstance; + } + } + } +} diff --git a/SSH_Test/Properties/Settings.settings b/SSH_Test/Properties/Settings.settings new file mode 100644 index 0000000..3964565 --- /dev/null +++ b/SSH_Test/Properties/Settings.settings @@ -0,0 +1,7 @@ + + + + + + + diff --git a/SSH_Test/SSH_Test.csproj b/SSH_Test/SSH_Test.csproj new file mode 100644 index 0000000..a6cc378 --- /dev/null +++ b/SSH_Test/SSH_Test.csproj @@ -0,0 +1,178 @@ + + + + + Debug + AnyCPU + {73DED4CD-B2B1-491E-87B7-BC1F11759C53} + Exe + SSH_Test + SSH_Test + v4.8 + 512 + true + true + publish\ + true + Disk + false + Foreground + 7 + Days + false + false + true + 0 + 1.0.0.%2a + false + false + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + packages\BouncyCastle.Cryptography.2.6.2\lib\net461\BouncyCastle.Cryptography.dll + + + packages\Microsoft.Bcl.AsyncInterfaces.8.0.0\lib\net462\Microsoft.Bcl.AsyncInterfaces.dll + + + packages\Microsoft.Extensions.DependencyInjection.Abstractions.8.0.2\lib\net462\Microsoft.Extensions.DependencyInjection.Abstractions.dll + + + packages\Microsoft.Extensions.Logging.Abstractions.8.0.3\lib\net462\Microsoft.Extensions.Logging.Abstractions.dll + + + packages\SSH.NET.2025.1.0\lib\net462\Renci.SshNet.dll + + + + packages\System.Buffers.4.5.1\lib\net461\System.Buffers.dll + + + + packages\System.Formats.Asn1.8.0.2\lib\net462\System.Formats.Asn1.dll + + + packages\System.Memory.4.5.5\lib\net461\System.Memory.dll + + + + packages\System.Numerics.Vectors.4.5.0\lib\net46\System.Numerics.Vectors.dll + + + packages\System.Runtime.CompilerServices.Unsafe.4.5.3\lib\net461\System.Runtime.CompilerServices.Unsafe.dll + + + packages\System.Threading.Tasks.Extensions.4.5.4\lib\net461\System.Threading.Tasks.Extensions.dll + + + packages\System.ValueTuple.4.5.0\lib\net47\System.ValueTuple.dll + + + + + + + + + + + + + + Form + + + FormConfiguration.cs + + + Form + + + FormCredential.cs + + + Form + + + FormProfile.cs + + + Form + + + TastList.cs + + + + + FormConfiguration.cs + + + FormCredential.cs + + + FormProfile.cs + + + TastList.cs + + + ResXFileCodeGenerator + Resources.Designer.cs + Designer + + + True + Resources.resx + + + + SettingsSingleFileGenerator + Settings.Designer.cs + + + True + Settings.settings + True + + + + + + + + False + Microsoft .NET Framework 4.8 %28x86 and x64%29 + true + + + False + .NET Framework 3.5 SP1 + false + + + + \ No newline at end of file diff --git a/SSH_Test/SSH_Test.csproj.user b/SSH_Test/SSH_Test.csproj.user new file mode 100644 index 0000000..d213892 --- /dev/null +++ b/SSH_Test/SSH_Test.csproj.user @@ -0,0 +1,13 @@ + + + + publish\ + + + + + + en-US + false + + \ No newline at end of file diff --git a/SSH_Test/SSH_Test.slnx b/SSH_Test/SSH_Test.slnx new file mode 100644 index 0000000..b505ab0 --- /dev/null +++ b/SSH_Test/SSH_Test.slnx @@ -0,0 +1,3 @@ + + + diff --git a/SSH_Test/TastList.Designer.cs b/SSH_Test/TastList.Designer.cs new file mode 100644 index 0000000..68d85ea --- /dev/null +++ b/SSH_Test/TastList.Designer.cs @@ -0,0 +1,197 @@ +namespace SSH_Test +{ + partial class TastList + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.bRunAll = new System.Windows.Forms.Button(); + this.dataGridViewTask = new System.Windows.Forms.DataGridView(); + this.buttonSave = new System.Windows.Forms.Button(); + this.buttonLoad = new System.Windows.Forms.Button(); + this.TaskNum = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.TaskDescription = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.TaskDevice = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.TaskIp = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.Port = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.Run = new System.Windows.Forms.DataGridViewButtonColumn(); + this.Credential = new System.Windows.Forms.DataGridViewButtonColumn(); + this.Profile = new System.Windows.Forms.DataGridViewButtonColumn(); + this.buttonConf = new System.Windows.Forms.Button(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridViewTask)).BeginInit(); + this.SuspendLayout(); + // + // bRunAll + // + this.bRunAll.Location = new System.Drawing.Point(782, 9); + this.bRunAll.Name = "bRunAll"; + this.bRunAll.Size = new System.Drawing.Size(92, 23); + this.bRunAll.TabIndex = 1; + this.bRunAll.Text = "Run All"; + this.bRunAll.UseVisualStyleBackColor = true; + this.bRunAll.Click += new System.EventHandler(this.bRunAll_Click); + // + // dataGridViewTask + // + this.dataGridViewTask.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridViewTask.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { + this.TaskNum, + this.TaskDescription, + this.TaskDevice, + this.TaskIp, + this.Port, + this.Run, + this.Credential, + this.Profile}); + this.dataGridViewTask.Location = new System.Drawing.Point(8, 41); + this.dataGridViewTask.Name = "dataGridViewTask"; + this.dataGridViewTask.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.CellSelect; + this.dataGridViewTask.Size = new System.Drawing.Size(1043, 397); + this.dataGridViewTask.TabIndex = 2; + this.dataGridViewTask.CellContentClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.dataGridViewTask_CellContentClick); + this.dataGridViewTask.CellEndEdit += new System.Windows.Forms.DataGridViewCellEventHandler(this.dataGridViewTask_CellEndEdit); + // + // buttonSave + // + this.buttonSave.Location = new System.Drawing.Point(114, 9); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(96, 23); + this.buttonSave.TabIndex = 3; + this.buttonSave.Text = "Save Task List"; + this.buttonSave.UseVisualStyleBackColor = true; + this.buttonSave.Click += new System.EventHandler(this.buttonSave_Click); + // + // buttonLoad + // + this.buttonLoad.Location = new System.Drawing.Point(12, 9); + this.buttonLoad.Name = "buttonLoad"; + this.buttonLoad.Size = new System.Drawing.Size(96, 23); + this.buttonLoad.TabIndex = 4; + this.buttonLoad.Text = "Load Tasklisk"; + this.buttonLoad.UseVisualStyleBackColor = true; + this.buttonLoad.Click += new System.EventHandler(this.buttonLoad_Click); + // + // TaskNum + // + this.TaskNum.HeaderText = "Task #"; + this.TaskNum.Name = "TaskNum"; + // + // TaskDescription + // + this.TaskDescription.HeaderText = "Description"; + this.TaskDescription.MinimumWidth = 50; + this.TaskDescription.Name = "TaskDescription"; + this.TaskDescription.Width = 400; + // + // TaskDevice + // + this.TaskDevice.HeaderText = "Device"; + this.TaskDevice.Name = "TaskDevice"; + // + // TaskIp + // + this.TaskIp.HeaderText = "IP"; + this.TaskIp.Name = "TaskIp"; + this.TaskIp.Resizable = System.Windows.Forms.DataGridViewTriState.True; + this.TaskIp.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.NotSortable; + this.TaskIp.ToolTipText = "IP address"; + // + // Port + // + this.Port.HeaderText = "Port"; + this.Port.Name = "Port"; + this.Port.ToolTipText = "Port SSH=22"; + this.Port.Width = 50; + // + // Run + // + this.Run.HeaderText = "Run"; + this.Run.Name = "Run"; + this.Run.Resizable = System.Windows.Forms.DataGridViewTriState.False; + this.Run.Text = "Run"; + this.Run.Width = 50; + // + // Credential + // + this.Credential.HeaderText = "Credential"; + this.Credential.Name = "Credential"; + this.Credential.Resizable = System.Windows.Forms.DataGridViewTriState.False; + this.Credential.Width = 80; + // + // Profile + // + this.Profile.HeaderText = "Profile"; + this.Profile.Name = "Profile"; + this.Profile.ReadOnly = true; + this.Profile.Resizable = System.Windows.Forms.DataGridViewTriState.True; + this.Profile.Width = 120; + // + // buttonConf + // + this.buttonConf.Location = new System.Drawing.Point(216, 9); + this.buttonConf.Name = "buttonConf"; + this.buttonConf.Size = new System.Drawing.Size(96, 23); + this.buttonConf.TabIndex = 5; + this.buttonConf.Text = "Configuration"; + this.buttonConf.TextImageRelation = System.Windows.Forms.TextImageRelation.ImageBeforeText; + this.buttonConf.UseVisualStyleBackColor = true; + this.buttonConf.Click += new System.EventHandler(this.buttonConf_Click); + // + // TastList + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(1055, 450); + this.Controls.Add(this.buttonConf); + this.Controls.Add(this.buttonLoad); + this.Controls.Add(this.buttonSave); + this.Controls.Add(this.dataGridViewTask); + this.Controls.Add(this.bRunAll); + this.Name = "TastList"; + this.Text = "Task List"; + this.Load += new System.EventHandler(this.fSSHTest_Load); + ((System.ComponentModel.ISupportInitialize)(this.dataGridViewTask)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + private System.Windows.Forms.Button bRunAll; + private System.Windows.Forms.DataGridView dataGridViewTask; + private System.Windows.Forms.Button buttonSave; + private System.Windows.Forms.Button buttonLoad; + private System.Windows.Forms.DataGridViewTextBoxColumn TaskNum; + private System.Windows.Forms.DataGridViewTextBoxColumn TaskDescription; + private System.Windows.Forms.DataGridViewTextBoxColumn TaskDevice; + private System.Windows.Forms.DataGridViewTextBoxColumn TaskIp; + private System.Windows.Forms.DataGridViewTextBoxColumn Port; + private System.Windows.Forms.DataGridViewButtonColumn Run; + private System.Windows.Forms.DataGridViewButtonColumn Credential; + private System.Windows.Forms.DataGridViewButtonColumn Profile; + private System.Windows.Forms.Button buttonConf; + } +} + diff --git a/SSH_Test/TastList.cs b/SSH_Test/TastList.cs new file mode 100644 index 0000000..11beefa --- /dev/null +++ b/SSH_Test/TastList.cs @@ -0,0 +1,528 @@ +using Renci.SshNet; +using Renci.SshNet.Common; +using System; +using System.Threading; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.IO; +using System.Linq; +using System.Linq.Expressions; +using System.Text; +using System.Text.RegularExpressions; +using System.Threading.Tasks; +using System.Windows.Forms; +using System.Xml; +using static System.Windows.Forms.VisualStyles.VisualStyleElement; + +namespace SSH_Test +{ + + + public partial class TastList : Form + { + + public List Tasks = new List(); + public cFtpInfo ftpInfo = new cFtpInfo("","","","","",""); + + public TastList() + { + InitializeComponent(); + + + + } + + private void fSSHTest_Load(object sender, EventArgs e) + { + } + + private void bRunAll_Click(object sender, EventArgs e) + { + + + } + + private void dataGridViewTask_CellContentClick(object sender, DataGridViewCellEventArgs e) + { + string host = ""; + string username = ""; + string password = ""; + string profile = ""; + + try + { + var currentTask = Tasks[e.RowIndex]; + host = currentTask.sTaskIP.ToString(); + username = currentTask.sUsername.ToString(); + password = currentTask.sPassword.ToString(); + switch (e.ColumnIndex) + { + case 5: + profile = currentTask.sProfile.ToString(); + cHostInfo hostInfo = new cHostInfo(); + hostInfo.host = host; + hostInfo.username = username; + hostInfo.password = password; + hostInfo.device = currentTask.sTaskDevice.ToString(); + switch (profile) + { + case "Cisco_Switch": + Thread thread1 = new Thread(new ParameterizedThreadStart(fSSHCisco)); + thread1.Start(hostInfo); + break; + case "Cisco_Switch_Tftp": + hostInfo.SftpIP = ftpInfo.sTftpIP; + + Thread thread2 = new Thread(new ParameterizedThreadStart(fSSHCisco_Tftp)); + thread2.Start(hostInfo); + break; + case "Cisco_Switch_Tftp_Startup": + hostInfo.SftpIP = ftpInfo.sTftpIP; + hostInfo.SftpPassword = ftpInfo.sTftpPassword; + hostInfo.SftpUsername = ftpInfo.sTftpUsername; + + + Thread thread3 = new Thread(new ParameterizedThreadStart(fSSHCisco_Tftp_Startup)); + thread3.Start(hostInfo); + break; + + default: + break; + + + } + + + + + break; + case 6: //call Credential + + FormCredential formCredential = new FormCredential(username, password); + formCredential.ShowDialog(); + if ((formCredential.Username != "") && (formCredential.Username != username)) + username = currentTask.sUsername = formCredential.Username; + if ((formCredential.Password != "") && formCredential.Password != password) + password = currentTask.sPassword = formCredential.Password; + + break; + case 7: //call Profile + + FormProfile formProfile = new FormProfile(profile); + formProfile.ShowDialog(); + profile = currentTask.sProfile = formProfile.sProfile; + dataGridViewTask.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = profile; + break; + + default: + break; + + } + } + catch ( Exception ex) + { + } + + + + + + + + + } + + private void dataGridViewTask_CellEndEdit(object sender, DataGridViewCellEventArgs e) + { + if (e.ColumnIndex != 5) + { + if (Tasks.Count < (e.RowIndex + 1)) + { + Tasks.Add(new cTask(e.RowIndex + 1, "", "", "", "", "", "","")); + } + switch (e.ColumnIndex) + { + case 0: + Tasks[e.RowIndex].iTaskNum = e.RowIndex + 1; + break; + case 1: + Tasks[e.RowIndex].sTaskDescription = (string)dataGridViewTask.Rows[e.RowIndex].Cells[e.ColumnIndex].Value; + break; + case 2: + Tasks[e.RowIndex].sTaskDevice = (string)dataGridViewTask.Rows[e.RowIndex].Cells[e.ColumnIndex].Value; + break; + case 3: + Tasks[e.RowIndex].sTaskIP = (string)dataGridViewTask.Rows[e.RowIndex].Cells[e.ColumnIndex].Value; + break; + case 4: + Tasks[e.RowIndex].uTaskPort = (string)dataGridViewTask.Rows[e.RowIndex].Cells[e.ColumnIndex].Value; + break; + case 5: + + break; + case 7: // Profile + Tasks[e.RowIndex].sProfile = (string)dataGridViewTask.Rows[e.RowIndex].Cells[e.ColumnIndex].Value; + break; + default: + break; + } + } + } + + private void buttonSave_Click(object sender, EventArgs e) + { + if (Tasks.Count > 1) + { + using (Stream stream = File.Open("tasklist.dat", FileMode.Create)) + { + var binaryFormatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter(); + binaryFormatter.Serialize(stream, Tasks); + } + using (Stream stream = File.Open("ftpInfo.dat", FileMode.Create)) + { + var binaryFormatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter(); + binaryFormatter.Serialize(stream, ftpInfo); + } + } + } + + private void buttonLoad_Click(object sender, EventArgs e) + { + using (Stream stream = File.Open("tasklist.dat", FileMode.Open)) + { + + var binaryFormatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter(); + Tasks = (List)binaryFormatter.Deserialize(stream); + } + using (Stream stream = File.Open("ftpInfo.dat", FileMode.Open)) + { + + var binaryFormatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter(); + ftpInfo = (cFtpInfo)binaryFormatter.Deserialize(stream); + } + + //clear TaskList + dataGridViewTask.Rows.Clear(); + + foreach (var task in Tasks) + { + DataGridViewRow row = (DataGridViewRow)dataGridViewTask.Rows[0].Clone(); + row.Cells[0].Value = task.iTaskNum; + row.Cells[1].Value = task.sTaskDescription; + row.Cells[2].Value = task.sTaskDevice; + row.Cells[3].Value = task.sTaskIP; + row.Cells[4].Value = task.uTaskPort; + row.Cells[7].Value = task.sProfile; + dataGridViewTask.Rows.Add(row); + + } + } + public class cHostInfo + { + public string device { get; set; } + public string host { get; set; } + public string username { get; set; } + public string password { get; set; } + public string SftpIP { get; set; } + public string SftpUsername { get; set; } + public string SftpPassword { get; set; } + } + public void fSSHCisco(object data) + { + cHostInfo hostinfo = (cHostInfo)data; + var client = new SshClient(hostinfo.host, hostinfo.username, hostinfo.password); + Console.WriteLine("From SSH_Test: Establishing a connection"); + client.Connect(); + Console.WriteLine(client.ConnectionInfo.ServerVersion); + string host = hostinfo.host; + string device = hostinfo.device; + string username = hostinfo.username; + string password = hostinfo.password; + + if (client.IsConnected) + { + uint i = 0; + var shellStream = client.CreateShellStream("xterm", 80, 24, 800, 600, 1024); + var output = ""; + var result = ""; + //Cisco SG300 + //wait for "User Name:" + output = shellStream.Expect(new Regex(@"Name:|name:")); + Console.WriteLine("From SSH_Test {0}: {1}", i++, output); + + //send username + shellStream.WriteLine(username); + + //wait for "Password:" + output = shellStream.Expect(new Regex(@"word:")); + Console.WriteLine("From SSH_Test {0}: {1}", i++, output); + + //send password + shellStream.WriteLine(password); + + //wait for "Prompt:" + output = shellStream.Expect(new Regex(@"#")); + Console.WriteLine("From SSH_Test {0}: {1}", i++, output); + + output = ""; + //send sh run + shellStream.WriteLine("sh run"); + //wait "" to send "space" and loop until get prompt + while (!Regex.IsMatch(output, "#")) + { + output = shellStream.Expect(new Regex(@"More||#")); + + shellStream.WriteLine(" "); + string[] lines = output.Split('\n'); + var output1 = ""; + for (int ii = 0; ii < (lines.Length - 1); ii++) + output1 += lines[ii]; + Console.WriteLine(output1); + result += output1; + } + //write to file + string datetime = DateTime.Now.ToString().Replace(":", ""); + datetime = datetime.Replace(" ", "_"); + // string filePath = string.Format("{0}_{1}.txt", currentTask.sTaskDevice, datetime.Replace("-", "")); + string filePath = string.Format("{0}_{1}.txt", device, datetime.Replace("-", "")); + try + { + // Write the string to the file, overwriting existing content if the file exists + File.WriteAllText(filePath, result); + System.Console.WriteLine($"Successfully wrote to {filePath}"); + } + catch (IOException ex) + { + System.Console.WriteLine($"An error occurred while writing to the file: {ex.Message}"); + } + } + + client.Disconnect(); + Console.WriteLine("From SSH_Test: Disconnected"); + } + public void fSSHCisco_Tftp(object data) + { + cHostInfo hostinfo = (cHostInfo)data; + var client = new SshClient(hostinfo.host, hostinfo.username, hostinfo.password); + Console.WriteLine("From SSH_Test: Establishing a connection"); + client.Connect(); + Console.WriteLine(client.ConnectionInfo.ServerVersion); + string host = hostinfo.host; + string device = hostinfo.device; + string username = hostinfo.username; + string password = hostinfo.password; + string sftpIp = hostinfo.SftpIP; + string sftpUsername = hostinfo.SftpUsername; + string sftpPassword = hostinfo.SftpPassword; + + + + if (client.IsConnected) + { + uint i = 0; + var shellStream = client.CreateShellStream("xterm", 80, 24, 800, 600, 1024); + var output = ""; + var result = ""; + //Cisco SG300 + //wait for "User Name:" + output = shellStream.Expect(new Regex(@"Name:|name:")); + Console.WriteLine("From SSH_Test {0}: {1}", i++, output); + + //send username + shellStream.WriteLine(username); + + //wait for "Password:" + output = shellStream.Expect(new Regex(@"word:")); + Console.WriteLine("From SSH_Test {0}: {1}", i++, output); + + //send password + shellStream.WriteLine(password); + + //wait for "Prompt:" + output = shellStream.Expect(new Regex(@"#")); + Console.WriteLine("From SSH_Test {0}: {1}", i++, output); + + output = ""; + //send enable + // shellStream.WriteLine("enable"); + // wait for "Prompt:" + // output = shellStream.Expect(new Regex(@"#")); + + + //create filename for running-config + string datetime = DateTime.Now.ToString().Replace(":", ""); + datetime = datetime.Replace(" ", "_"); + // string filePath = string.Format("{0}_{1}.txt", currentTask.sTaskDevice, datetime.Replace("-", "")); + string filePath = string.Format("{0}_{1}.txt", device, datetime.Replace("-", "")); + + + + string command = string.Format("copy running-config tftp://{0}/{1}", sftpIp, filePath); + Console.WriteLine("From SSH_Test {0}: {1}", i++, command); + shellStream.WriteLine(command); + //send sftp command + + //wait "" to send "space" and loop until get prompt + while (!Regex.IsMatch(output, "#")) + { + output = shellStream.Expect(new Regex(@"More||#")); + + shellStream.WriteLine(" "); + string[] lines = output.Split('\n'); + var output1 = ""; + for (int ii = 0; ii < (lines.Length - 1); ii++) + output1 += lines[ii]; + Console.WriteLine(output1); + result += output1; + } + + } + + client.Disconnect(); + Console.WriteLine("From SSH_Test: Disconnected"); + } + + public void fSSHCisco_Tftp_Startup(object data) + { + cHostInfo hostinfo = (cHostInfo)data; + var client = new SshClient(hostinfo.host, hostinfo.username, hostinfo.password); + Console.WriteLine("From SSH_Test: Establishing a connection"); + client.Connect(); + Console.WriteLine(client.ConnectionInfo.ServerVersion); + string host = hostinfo.host; + string device = hostinfo.device; + string username = hostinfo.username; + string password = hostinfo.password; + string sftpIp = hostinfo.SftpIP; + string sftpUsername = hostinfo.SftpUsername; + string sftpPassword = hostinfo.SftpPassword; + + + + if (client.IsConnected) + { + uint i = 0; + var shellStream = client.CreateShellStream("xterm", 80, 24, 800, 600, 1024); + var output = ""; + var result = ""; + //Cisco SG300 + //wait for "User Name:" + output = shellStream.Expect(new Regex(@"Name:|name:")); + Console.WriteLine("From SSH_Test {0}: {1}", i++, output); + + //send username + shellStream.WriteLine(username); + + //wait for "Password:" + output = shellStream.Expect(new Regex(@"word:")); + Console.WriteLine("From SSH_Test {0}: {1}", i++, output); + + //send password + shellStream.WriteLine(password); + + //wait for "Prompt:" + output = shellStream.Expect(new Regex(@"#")); + Console.WriteLine("From SSH_Test {0}: {1}", i++, output); + + output = ""; + //send enable + // shellStream.WriteLine("enable"); + // wait for "Prompt:" + // output = shellStream.Expect(new Regex(@"#")); + + + //create filename for running-config + string datetime = DateTime.Now.ToString().Replace(":", ""); + datetime = datetime.Replace(" ", "_"); + // string filePath = string.Format("{0}_{1}.txt", currentTask.sTaskDevice, datetime.Replace("-", "")); + string filePath = string.Format("{0}_{1}.txt", device, datetime.Replace("-", "")); + + + + string command = string.Format("copy startup-config tftp://{0}/{1}", sftpIp, filePath); + Console.WriteLine("From SSH_Test {0}: {1}", i++, command); + shellStream.WriteLine(command); + //send sftp command + + //wait "" to send "space" and loop until get prompt + while (!Regex.IsMatch(output, "#")) + { + output = shellStream.Expect(new Regex(@"More||#")); + + shellStream.WriteLine(" "); + string[] lines = output.Split('\n'); + var output1 = ""; + for (int ii = 0; ii < (lines.Length - 1); ii++) + output1 += lines[ii]; + Console.WriteLine(output1); + result += output1; + } + + } + + client.Disconnect(); + Console.WriteLine("From SSH_Test: Disconnected"); + } + + private void buttonConf_Click(object sender, EventArgs e) + { + FormConfiguration formConfiguration = new FormConfiguration(ftpInfo.sTftpIP, ftpInfo.sSftpIP, ftpInfo.sSftpUsername, ftpInfo.sSftpPassword); + formConfiguration.ShowDialog(); + ftpInfo.sTftpIP = formConfiguration.Tftp_IP; + ftpInfo.sSftpIP = formConfiguration.Sftp_IP; + ftpInfo.sSftpUsername = formConfiguration.Sftp_Username; + ftpInfo.sSftpPassword = formConfiguration.Sftp_Password; + + } + + [Serializable] + public class cTask + { + public int iTaskNum { get; set; } + public String sTaskDescription { get; set; } + public String sTaskDevice { get; set; } + public String sTaskIP { get; set; } + public String uTaskPort { get; set; } + public String sUsername { get; set; } + public String sPassword { get; set; } + public String sProfile { get; set; } + public cTask(int iTaskNum, string uTaskDescription, string uTaskDevice, string uTaskIP, string uTaskPort, string sUsername, string sPassword, string sProfile) + { + this.iTaskNum = iTaskNum; + this.sTaskDescription = uTaskDescription; + this.sTaskDevice = uTaskDevice; + this.sTaskIP = uTaskIP; + this.uTaskPort = uTaskPort; + this.sUsername = sUsername; + this.sPassword = sPassword; + } + } + + + [Serializable] + public class cFtpInfo + { + + public String sTftpIP { get; set; } + public String sTftpUsername { get; set; } + public String sTftpPassword { get; set; } + public String sSftpIP { get; set; } + public String sSftpUsername { get; set; } + public String sSftpPassword { get; set; } + public cFtpInfo( string TftpIP, string TftpUsername, string TftpPassword, string SftpIP, String SftpUsername, String SftPassword) + { + this.sTftpIP = TftpIP; + this.sTftpUsername = TftpUsername; + this.sTftpPassword = TftpPassword; + this.sSftpIP = SftpIP; + this.sSftpUsername = SftpUsername; + this.sSftpPassword = SftPassword; + + + } + } + } + +} \ No newline at end of file diff --git a/SSH_Test/TastList.resx b/SSH_Test/TastList.resx new file mode 100644 index 0000000..7d33532 --- /dev/null +++ b/SSH_Test/TastList.resx @@ -0,0 +1,144 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + True + + + True + + + True + + + True + + + True + + + True + + + True + + + True + + \ No newline at end of file diff --git a/SSH_Test/packages.config b/SSH_Test/packages.config new file mode 100644 index 0000000..0f2b537 --- /dev/null +++ b/SSH_Test/packages.config @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + \ No newline at end of file