// 探測ONU-ID protected void Button1_Click(object sender, EventArgs e) { try { if (Pr_Slot_Box.Text != "" && Pr_Port_Box.Text != "" && Pr_Area_DropDownList.Text != "" && Pr_Olt_DropDownList.Text != "") { OLT_DIC OLTIP = new OLT_DIC(); using (var client = new SshClient(OLTIP.Find_DIC(Pr_Olt_DropDownList.Text), 22, "admin", "123")) { // 建立連線 client.Connect(); // 連線參數 var stream = client.CreateShellStream("", 0, 0, 0, 0, 0); string GP = $@" en config t gp " ; string GP_Port = $@" gp {Pr_Slot_Box.Text}/{Pr_Port_Box.Text} " ; Thread.Sleep(3000); stream.WriteLine(GP); Thread.Sleep(500); stream.WriteLine(GP_Port); Thread.Sleep(500); stream.WriteLine("sh onu info"); Thread.Sleep(500); stream.WriteLine(Environment.NewLine); Thread.Sleep(500); int x = 0; int y = 0; // 輸出結果 string line; int[] count = new int[38]; while ((line = stream.ReadLine(TimeSpan.FromSeconds(2))) != null) { int id = line.IndexOf("ctive"); if (id != -1) { Console.WriteLine(line); var lines = line.Split('|'); //Console.WriteLine(lines[1]); Console.WriteLine(int.Parse(lines[1].Substring(2, 2))); int id2 = line.IndexOf("Active"); { if (id2 != -1) { if (line.Substring(64, 1) == " ") { count[37] = int.Parse(lines[1].Substring(2, 2)); y = 1; Console.WriteLine(line.Substring(64, 1)); Console.WriteLine("印出!!!"); } } } count[int.Parse(lines[1].Substring(2, 2))] = int.Parse(lines[1].Substring(2, 2)); x++; } } // 結束連線 if (x == 0) { Pr_Onu_Box.Text = "1"; } else { if (y != 1) { for (int i = 1; i < 37; i++) { Console.WriteLine(count[2]); Console.WriteLine(count[1]); if (count[2] != 0 && count[1] == 0) { x = 1; break; } else if (count[i] != 0) { x = count[i]; } else { x++; break; } } Pr_Onu_Box.Text = "" + (x); Console.WriteLine(x); } else { Pr_Onu_Box.Text = "" + count[37]; } } } //WMPLib.WindowsMediaPlayer wplayer1 = new WMPLib.WindowsMediaPlayer(); //wplayer1.URL = $@"{AppDomain.CurrentDomain.BaseDirectory}DATA/MIC06.mp3"; //wplayer1.controls.play(); } else { //MessageBox.Show("你 OLT位置 或 Slot 或 Port 沒填?"); } } catch (Exception) { } }
// ====================================開通按鈕==================================== protected void auto_button_Click(object sender, EventArgs e) { OLT_DIC OLTIP = new OLT_DIC(); string old = ""; string GP = $@" en config t gp " ; string GP_Port = $@" gp {ONT_Profile.Slot}/{ONT_Profile.Port} " ; string Show_Old = $@" show running-config gpon-olt {ONT_Profile.Slot}/{ONT_Profile.Port} " ; using (var client = new SshClient(OLTIP.Find_DIC(Pr_Olt_DropDownList.Text), 22, "admin", "123")) { // 建立連線 client.Connect(); // 連線參數 var stream = client.CreateShellStream("", 0, 0, 0, 0, 0); Thread.Sleep(4500); stream.WriteLine(GP); Thread.Sleep(1000); stream.WriteLine(GP_Port); Thread.Sleep(1000); stream.WriteLine(Show_Old); Thread.Sleep(2000); stream.WriteLine(Environment.NewLine); Thread.Sleep(2000); // 輸出結果 string line; while ((line = stream.ReadLine(TimeSpan.FromSeconds(2))) != null) { int id = line.IndexOf("8272OLT"); if (id < 0) { Console.WriteLine(line); old += line + "\r\n"; } } // 結束連線 stream.Close(); client.Disconnect(); } Thread.Sleep(1000); using (var client = new SshClient(OLTIP.Find_DIC(Pr_Olt_DropDownList.Text), 22, "admin", "123")) { // 建立連線 client.Connect(); // 連線參數 var stream = client.CreateShellStream("", 0, 0, 0, 0, 0); Thread.Sleep(4500); stream.WriteLine(GP); Thread.Sleep(1500); stream.WriteLine(ONT_Profile.Dba_profile()); Thread.Sleep(1500); stream.WriteLine(ONT_Profile.Vlan_profile()); Thread.Sleep(1500); stream.WriteLine(ONT_Profile.Traffic_profile()); Thread.Sleep(1500); stream.WriteLine(ONT_Profile.Onu_profile()); Thread.Sleep(1500); stream.WriteLine(GP_Port); Thread.Sleep(1500); stream.WriteLine(ONT_Profile.GPON_OLT()); Thread.Sleep(1500); stream.WriteLine("exit"); stream.WriteLine("bridge"); Thread.Sleep(1500); stream.WriteLine(ONT_Profile.OLT_Vlan()); // 輸出結果 string line; while ((line = stream.ReadLine(TimeSpan.FromSeconds(2))) != null) { Console.WriteLine(line); } // 結束連線 stream.Close(); client.Disconnect(); //MessageBox.Show("開通完畢!"); StreamWriter str1 = new StreamWriter($@"{AppDomain.CurrentDomain.BaseDirectory}Profile輸出.txt"); str1.WriteLine(Pr_output_richTextBox.Text); str1.Close(); StreamWriter str2 = new StreamWriter($@"{AppDomain.CurrentDomain.BaseDirectory}OLD_Detail.txt"); str2.WriteLine(old); str2.Close(); Pr_auto_button.Enabled = false; } }