Пример #1
0
 private void flushItems(InetAddress setInet)
 {
     //绑定数据源,并指定要展示的列和值得绑定
     cbbIps.DataSource    = null;
     cbbIps.DataSource    = listItem;
     cbbIps.DisplayMember = "ip";
     cbbIps.ValueMember   = "ip";
     if (setInet != null)
     {
         cbbIps.SelectedItem = setInet;
     }
 }
Пример #2
0
 private void setTextVal(InetAddress iad)
 {
     if (iad == null)
     {
         return;
     }
     tbIp.Text         = iad.ip;
     tbSubNetMask.Text = iad.subNet;
     tbGateWay.Text    = iad.gateWay;
     tbDns.Text        = iad.dns;
     tbDns2.Text       = iad.dns2;
 }
Пример #3
0
        private void button2_Click(object sender, EventArgs e)
        {
            List <String> cmd = new List <String>();

            if (rbSet.Checked)
            {
                InetAddress setInet = new InetAddress();
                setInet.ip      = tbIp.Text.Trim();
                setInet.subNet  = tbSubNetMask.Text.Trim();
                setInet.gateWay = tbGateWay.Text.Trim();
                setInet.dns     = tbDns.Text.Trim();
                setInet.dns2    = tbDns2.Text.Trim();

                if (!IsIpaddress(setInet.ip))
                {
                    MessageBox.Show("请设置正确IP!", "提示", MessageBoxButtons.OK);
                    return;
                }
                //手动设置IP信息
                cmd.Add("netsh interface ip set address " + lkName + " source=static addr=" + setInet.ip + " mask=" + setInet.subNet + " gateway=" + setInet.gateWay);
                cmd.Add("netsh interface ip set dns " + lkName + " source=static addr=" + setInet.dns + " register=primary");
                if (setInet.dns2 != null && setInet.dns2 != "")
                {
                    cmd.Add("netsh interface ip add dns " + lkName + " addr=" + setInet.dns2 + " index=2");
                }
                setInetAddress(cmd);
                if (listItem.Find(it => { return(it.ip.Equals(setInet.ip)); }) == null)
                {
                    listItem.Add(setInet);
                }
                flushItems(setInet);
                reWriteData();
            }
            else if (rbCurrent.Checked)
            {
                getCurrent();
                setTextVal(current);
            }
            else
            {
                //设置自动获取IP信息
                cmd.Add("netsh interface ip set address " + lkName + " DHCP");
                cmd.Add("netsh interface ip set dns " + lkName + " DHCP");
                setInetAddress(cmd);
            }
            MessageBox.Show("操作成功!", "提示", MessageBoxButtons.OK);
        }
Пример #4
0
        private void initHistory()
        {
            try
            {
                if (!File.Exists(temp))
                {
                    return;
                }

                string ipHistory = File.ReadAllText(temp);
                if (ipHistory != null && !"".Equals(ipHistory))
                {
                    string[] adrss = ipHistory.Split(new char[] { '#' });
                    listItem.Clear();
                    for (int i = 0; i < adrss.Count(); i++)
                    {
                        if (adrss[i] == null || "".Equals(adrss[i]))
                        {
                            continue;
                        }
                        string[]    items   = adrss[i].Split(new char[] { '-' });
                        InetAddress setInet = new InetAddress();
                        setInet.ip      = items[0];
                        setInet.subNet  = items[1];
                        setInet.gateWay = items[2];
                        setInet.dns     = items[3];
                        setInet.dns2    = (items.Length > 4 && !String.IsNullOrEmpty(items[4])) ? items[4] : null;
                        listItem.Add(setInet);
                    }
                    flushItems(null);
                }
            }
            catch (Exception e)
            {
                MessageBox.Show("读取文件异常:" + e, "提示", MessageBoxButtons.OK);
            }
        }