Exemplo n.º 1
0
        private Panel GetInterfaceStatusPanel(Control parent, InterfaceStatus ifs)
        {
            // 接口状态容器
            Panel panel = new Panel();

            panel.Width       = parent.Width - 25;
            panel.Height      = 50;
            panel.Anchor      = AnchorStyles.Right;
            panel.Tag         = ifs.Tag;
            panel.BorderStyle = BorderStyle.FixedSingle;
            panel.BackColor   = ifs.OnLine ? Color.LightGreen : Color.Pink;
            // 顶端接口名
            Label label = new Label();

            label.Text      = ifs.Tag;
            label.Font      = new Font(new FontFamily("Consolas"), 15, FontStyle.Bold);
            label.TextAlign = ContentAlignment.MiddleCenter;
            label.Width     = panel.Width;
            panel.Controls.Add(label);
            // 中间水平分割线
            Label splitLine = new Label();

            splitLine.Width     = panel.Width - 12;
            splitLine.Top       = 25;
            splitLine.BackColor = Color.Gray;
            splitLine.Height    = 1;
            splitLine.Left      = 5;
            panel.Controls.Add(splitLine);
            // 接口连接用户
            Label ifconn = new Label();

            ifconn.Text      = ifs.OnLine ? ifs.UserName : "******";
            ifconn.Font      = new Font(new FontFamily("Consolas"), 10);
            ifconn.TextAlign = ContentAlignment.MiddleCenter;
            ifconn.Width     = panel.Width;
            ifconn.Top       = 26;
            panel.Controls.Add(ifconn);

            return(panel);
        }
Exemplo n.º 2
0
 private void backgroundWorkerStatus_DoWork(object sender, DoWorkEventArgs e)
 {
     while (true)
     {
         try
         {
             // 获取接口状态
             String uciCom = exec.RunCommand("uci show network | grep -E \"(network\\.)\\w+(\\.proto='pppoe')\" | cut -d . -f 2");
             ifList = uciCom.Split(new char[] { '\n' }, StringSplitOptions.RemoveEmptyEntries);
             List <InterfaceStatus> list = new List <InterfaceStatus>();
             foreach (String ifname in ifList)
             {
                 String          eth = exec.RunCommand("uci show network." + ifname + ".ifname | cut -d = -f 2 | cut -d \\' -f 2");
                 String          res = exec.RunCommand("ifconfig | grep pppoe-" + ifname);
                 InterfaceStatus ifs = new InterfaceStatus(ifname, false);
                 ifs.Eth = eth;
                 if (!res.Trim().Equals(""))
                 {
                     String user = exec.RunCommand("uci show network." + ifname + ".username | cut -d = -f 2 | cut -c 13-23");
                     ifs.UserName = user;
                     ifs.OnLine   = true;
                 }
                 list.Add(ifs);
             }
             if (backgroundWorkerStatus.CancellationPending)
             {
                 exec.Close();
                 break;
             }
             this.Invoke(new UpdateInterfaceStatucCallback(UpdateInterfaceStatus), list);
         } catch (Exception ex)
         {
             Console.WriteLine(ex.Message);
         }
         Thread.Sleep(1000);
     }
 }