Esempio n. 1
0
 // Get ip address from list, match if mac and ipversion match
 public static bool getIPseting(string mac, string ipversion, ref IpSettingItem settings)
 {
     foreach (var ipsetting in iplist)
     {
         if (ipsetting.MAC == mac && ipsetting.IPVERSION == ipversion)
         {
             settings.DHCPENABLE = ipsetting.DHCPENABLE;
             settings.IP         = ipsetting.IP;
             settings.GATEWAY    = ipsetting.GATEWAY;
             settings.MASK       = ipsetting.MASK;
             return(true);
         }
     }
     return(false);
 }
Esempio n. 2
0
        private void UnsetStaticIpv6Setting()
        {
            string macaddr = mac.value;

            resetError();

            foreach (ManagementObject nic in WmiBase.Singleton.Win32_NetworkAdapterConfiguration)
            {
                if (!(bool)nic["ipEnabled"])
                {
                    continue;
                }

                if (nic["macAddress"].ToString().ToUpper() != macaddr.ToUpper())
                {
                    continue;
                }

                IpSettingItem settings = new IpSettingItem(nic["macAddress"].ToString(), "IPV6", "", "", "", "");
                if (IpSettings.getIPseting(nic["macAddress"].ToString(), "IPV6", ref settings) == false)
                {
                    return;
                }

                try{
                    string argument = "interface ipv6 reset";
                    netshInvoke(argument);
                    IpSettings.removeIPseting(nic["macAddress"].ToString(), "IPV6");
                }
                catch (Exception e)
                {
                    errorCode.value = "1";
                    errorMsg.value  = e.ToString();

                    wmisession.Log("Exception " + e.ToString());
                    return;
                }
            }
        }
Esempio n. 3
0
        private void UnsetStaticIpv4Setting()
        {
            string macaddr = mac.value;

            resetError();

            foreach (ManagementObject nic in WmiBase.Singleton.Win32_NetworkAdapterConfiguration)
            {
                if (!(bool)nic["ipEnabled"])
                {
                    continue;
                }

                if (!NicUtil.macsMatch(macaddr, nic["macAddress"].ToString()))
                {
                    continue;
                }

                IpSettingItem settings = new IpSettingItem(nic["macAddress"].ToString(), "IPV4", "", "", "", "");
                if (IpSettings.getIPseting(nic["macAddress"].ToString(), "IPV4", ref settings) == false)
                {
                    return;
                }

                try{
                    setIpv4Network(nic, "EnableDHCP", null, "set back to dhcp");
                    IpSettings.removeIPseting(nic["macAddress"].ToString(), "IPV4");
                }
                catch (Exception e)
                {
                    errorCode.value = "1";
                    errorMsg.value  = e.ToString();

                    wmisession.Log("Exception " + e.ToString());
                    return;
                }
            }
        }
 // Get ip address from list, match if mac and ipversion match
 public static bool getIPseting(string mac, string ipversion, ref IpSettingItem settings)
 {
     foreach (var ipsetting in iplist)
     {
         if (ipsetting.MAC == mac && ipsetting.IPVERSION == ipversion)
         {
             settings.DHCPENABLE = ipsetting.DHCPENABLE;
             settings.IP = ipsetting.IP;
             settings.GATEWAY = ipsetting.GATEWAY;
             settings.MASK = ipsetting.MASK;
             return true;
         }
     }
     return false;
 }
        private void UnsetStaticIpv6Setting()
        {
            string macaddr = mac.value;

            resetError();

            foreach (ManagementObject nic in WmiBase.Singleton.Win32_NetworkAdapterConfiguration)
            {
                if (!(bool)nic["ipEnabled"])
                    continue;

                if (nic["macAddress"].ToString().ToUpper() != macaddr.ToUpper())
                    continue;

                IpSettingItem settings = new IpSettingItem(nic["macAddress"].ToString(), "IPV6", "", "", "", "");
                if (IpSettings.getIPseting(nic["macAddress"].ToString(), "IPV6", ref settings) == false)
                    return;

                try{
                    string argument = "interface ipv6 reset";
                    netshInvoke(argument);
                    IpSettings.removeIPseting(nic["macAddress"].ToString(), "IPV6");
                }
                catch (Exception e)
                {
                    errorCode.value = "1";
                    errorMsg.value = e.ToString();

                    wmisession.Log("Exception " + e.ToString());
                    return;
                }
            }
        }
        private void UnsetStaticIpv4Setting()
        {
            string macaddr = mac.value;

            resetError();

            foreach (ManagementObject nic in WmiBase.Singleton.Win32_NetworkAdapterConfiguration)
            {
                if (!(bool)nic["ipEnabled"])
                    continue;

                if (nic["macAddress"].ToString().ToUpper() != macaddr.ToUpper())
                    continue;

                IpSettingItem settings = new IpSettingItem(nic["macAddress"].ToString(), "IPV4", "", "", "", "");
                if (IpSettings.getIPseting(nic["macAddress"].ToString(), "IPV4", ref settings) == false)
                    return;

                try{
                    setIpv4Network(nic, "EnableDHCP", null, "set back to dhcp");
                    IpSettings.removeIPseting(nic["macAddress"].ToString(), "IPV4");
                }
                catch (Exception e)
                {
                    errorCode.value = "1";
                    errorMsg.value = e.ToString();

                    wmisession.Log("Exception " + e.ToString());
                    return;
                }
            }
        }