Exemplo n.º 1
0
        private void BtnUpdate_Click(object sender, EventArgs e)
        {
            string NicName = (string)CboNic.SelectedItem;
            string IpAdd   = TextIP.Text;
            string SubNet  = TextSubnet.Text;
            string Gateway = TextGateway.Text;
            string dnses   = TextDNS.Text;

            try
            {
                WMIHelper.SetIP(NicName, IpAdd, SubNet, Gateway, dnses);
                RetSettings();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Unable to set IP \nError : " + ex.Message);
            }
        }
Exemplo n.º 2
0
        private void btnIPSet_Click(object sender, EventArgs e)
        {
            string[] ipaddrs, masks, gateways, dns;
            string   currentIps = null;

            WMIHelper.GetIP(_wlnMgr.HostedNetworkInterfaceGuid, out ipaddrs, out masks, out gateways, out dns);
            ipaddrs = (ipaddrs ?? Enumerable.Empty <String>()).Where(_ => RegexIP.IsMatch(_)).ToArray();
            if (ipaddrs.Any())
            {
                currentIps = String.Join(" | ", ipaddrs);
            }
            bool ok = false;

            do
            {
                string ipAddr = Interaction.InputBox("输入IP地址:", currentIps == null ? "设置IP" : "当前IP:" + currentIps).Replace(" ", "");
                if (ipAddr.Length == 0)
                {
                    ok = true;
                }
                else
                {
                    if (!RegexIP.IsMatch(ipAddr))
                    {
                        this.Warn("IP地址格式不正确!");
                        ok = false;
                    }
                    else
                    {
                        WMIHelper.SetIP(_wlnMgr.HostedNetworkInterfaceGuid, ipAddr, "255.255.255.0", "", "");
                        this.Info("设置成功!");
                        ok = true;
                    }
                }
            } while (!ok);
        }