Exemplo n.º 1
0
 /// <summary>
 /// 获得第一个可用的网卡
 /// </summary>
 /// <returns></returns>
 public NetCard getEnableCard()
 {
     this.netCardDic = this.netCards.getAllNetCard();
     //遍历网卡写入
     foreach (KeyValuePair<string, NetCard> kv in this.netCardDic)
     {
         NetCard netcard = kv.Value;
         if (!netcard.isDrop() && netcard.isEnableIp())
         {
             return netcard;
         }
     }
     return null;
 }
Exemplo n.º 2
0
        private void SkinFrm_Load(object sender, EventArgs e)
        {
            //计算并设置程序起始位置
            this.StartPosition = FormStartPosition.Manual;
            int SW = System.Windows.Forms.SystemInformation.WorkingArea.Width;
            int SH = System.Windows.Forms.SystemInformation.WorkingArea.Height;
            int FW = this.Width;
            int FH = this.Height;
            int x  = SW - FW - 20;
            int y  = SH - FH;

            this.Location = (Point) new Size(x, y);

            //获得这个点的颜色反色
            Color pointColor     = Tools.getDeskTopPixelColor(x + 10, y + 10);
            int   pointColorArgb = pointColor.ToArgb();
            int   R = 0xFF & pointColorArgb;
            int   G = 0xFF00 & pointColorArgb;

            G >>= 8;
            int B = 0xFF0000 & pointColorArgb;

            B >>= 16;

            R = 255 - R;
            G = 255 - G;
            B = 255 - B;
            Color newColor = Color.FromArgb(0, R, G, B);

            //设置控件颜色为反色
            ip0_lab.ForeColor    = newColor;
            iNode0_lab.ForeColor = newColor;

            ip0_lab.ForeColor    = Color.WhiteSmoke;
            iNode0_lab.ForeColor = Color.WhiteSmoke;

            if (netCard.isEnableIp())
            {
                ip0_lab.Text = "IP地址:" + netCard.Ip;
            }
            else
            {
                ip0_lab.Text = "IP地址:" + localIpDic["ip"] + "(不可用)";
            }


            iNode0_lab.Text = "iNode账号:" + Tools.getiNodeUsername();
        }
Exemplo n.º 3
0
        private void btn_changeIp_Click(object sender, EventArgs e)
        {
            cmdM cmdm = () => pm.changeIp();

            this.BeginInvoke(cmdm);
            MessageBox.Show("修改成功!");
            //重新读取面板
            NetCard netcard = pm.readIpPanel();

            //判断更改后的IP能否ping通,如果能,则保存新的ip配置
            System.Threading.Timer threadTimer = new System.Threading.Timer(new System.Threading.TimerCallback(delegate {
                NetworkDoctorBackObj backObj = networkDoctor.checkNetwork(netcard);
                if (netcard.isEnableIp() && backObj.Status)
                {
                    Tools.updatePcInfo(db, netcard);
                }
            }), null, 8000, 0);
        }
Exemplo n.º 4
0
        private void initPanel()
        {
            //遍历网卡填入下拉列表,同时判断是否有设置合适的网卡
            foreach (KeyValuePair<string, NetCard> kv in this.netCardDic)
            {
                this.comboBox.Items.Add(kv.Key);
                NetCard netcard = kv.Value;
                //if (this.isEnable) continue;
                if (!netcard.isDrop() && netcard.isEnableIp())
                {
                    this.isEnable = true;
                    this.selectedNetCardName = netcard.Name;
                    writeIpPanel();

                }
            }
            //如果没找到符合规定的网卡,那么就选择默认第一个
            if (!this.isEnable && comboBox.Items.Count>0)
            {
                this.selectedNetCardName = comboBox.Items[0].ToString();
                writeIpPanel();
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// 检查IP地址是否设置正确
        /// </summary>
        /// <returns></returns>
        public NetworkDoctorBackObj checkIp()
        {
            NetworkDoctorBackObj backObj = new NetworkDoctorBackObj("ip");

            backObj.Status = true;
            statusUI(1, "start", true);
            refreshUI(1, "msg", "开始检查");
            Thread.Sleep(1000);

            //判断是否有NetCard符合ip规则
            string  enableNetCardName = "";
            NetCard enableNetCard     = null;

            foreach (KeyValuePair <string, NetCard> kv in netCardDic)
            {
                NetCard netCard = kv.Value;
                if (netCard.isEnableIp())
                {
                    enableNetCardName = kv.Key;
                    enableNetCard     = kv.Value;
                }
            }

            //检查IP地址是否可用
            refreshUI(1, "msg", "检查IP地址是否可用");
            if (enableNetCardName == "")
            {
                refreshUI(1, "msg", "发现本地ip地址设置错误..");
                backObj.addMsg("发现本地ip地址设置错误..\r\n");
                backObj.Status = false;
                if (this.localIpDic != null && this.localIpDic["netCardName"] != "")
                {
                    refreshUI(1, "msg", "尝试从本地恢复正确的IP配置..");
                    backObj.addMsg("尝试从本地恢复正确的IP配置..\r\n");
                    if (this.netCardDic.ContainsKey(this.localIpDic["netCardName"]))
                    {
                        this.netCard = this.netCardDic[this.localIpDic["netCardName"]];
                        this.netCard.setIp(this.localIpDic["ip"], this.localIpDic["mask"], this.localIpDic["gateway"]);
                        refreshUI(1, "msg", "检查IP是否设置成功..");
                        backObj.addMsg("检查IP是否设置成功..\r\n");
                        this.netCard = refreshNetCard(this.netCard.Name);
                        if (!this.netCard.isEnableIp())
                        {
                            refreshUI(1, "msg", "IP地址设置失败..");
                            backObj.addMsg("IP地址设置失败..\r\n");
                            backObj.addSugest("请尝试手动设置IP地址\r\n");
                            statusUI(1, "end", false);
                        }
                        else
                        {
                            refreshUI(1, "msg", "IP地址设置成功!");
                            statusUI(1, "end", true);
                            backObj.addMsg("IP地址正常\r\n");
                            backObj.Status = true;
                        }
                    }
                    else
                    {
                        refreshUI(1, "msg", "本地IP配置未存储,无法恢复");
                        Thread.Sleep(1000);
                        refreshUI(1, "msg", "失败");
                        statusUI(1, "end", false);
                    }
                }
            }
            //检查子网掩码是否可用
            //refreshUI(1, "msg", "检查子网掩码是否可用");
            //if (enableNetCard.isEnableMask())
            //{
            //    refreshUI(1, "msg", "子网掩码设置错误,尝试重新设置子网掩码..");
            //    backObj.addMsg("子网掩码设置错误,尝试重新设置子网掩码..\r\n");
            //    enableNetCard.setIp(enableNetCard.Ip, "255.255.255.0",enableNetCard.Gateway);
            //    refreshUI(1, "msg", "检查子网掩码是否设置成功..");
            //    backObj.addMsg("检查子网掩码是否设置成功..\r\n");
            //    this.netCard = refreshNetCard(enableNetCardName);
            //    if (!this.netCard.isEnableIp())
            //    {
            //        refreshUI(1, "msg", "子网掩码设置失败..");
            //        backObj.addMsg("子网掩码设置失败..\r\n");
            //        backObj.addSugest("请尝试手动设置子网掩码\r\n");
            //        statusUI(1, "end", false);
            //        return backObj;
            //    }
            //    else
            //    {
            //        refreshUI(1, "msg", "子网掩码设置成功!");
            //        statusUI(1, "end", true);
            //        backObj.addMsg("子网掩码正常\r\n");
            //        backObj.Status = true;
            //    }
            //}
            //检查默认网关是否可用
            refreshUI(1, "msg", "检查默认网关是否正确");
            if (enableNetCard != null)
            {
                string[] ipArr = enableNetCard.Ip.Split(new char[] { '.' });
                ipArr[3] = "1";
                string theoryGateway = string.Join(".", ipArr);
                if (enableNetCard.isEnableGateway())
                {
                    refreshUI(1, "msg", "网关设置错误,尝试重新设置网关..");
                    backObj.addMsg("网关设置错误,尝试重新设置网关..\r\n");
                    enableNetCard.setIp(enableNetCard.Ip, enableNetCard.Mask, theoryGateway);
                    refreshUI(1, "msg", "检查网关是否设置成功..");
                    backObj.addMsg("检查网关是否设置成功..\r\n");
                    this.netCard = refreshNetCard(enableNetCardName);
                    if (!this.netCard.isEnableGateway())
                    {
                        refreshUI(1, "msg", "网关地址设置失败..");
                        backObj.addMsg("网关地址设置失败..\r\n");
                        backObj.addSugest("请尝试手动设置网关地址\r\n");
                        statusUI(1, "end", false);
                        return(backObj);
                    }
                    else
                    {
                        refreshUI(1, "msg", "网关地址设置成功!");
                        statusUI(1, "end", true);
                        backObj.addMsg("网关地址正常\r\n");
                        backObj.Status = true;
                    }
                }
            }

            refreshUI(1, "msg", "正常");
            statusUI(1, "end", true);
            backObj.addMsg("IP地址正常\r\n");
            //任务完成了界面的返回
            TaskStepCallBack(backObj);
            return(backObj);
        }