addIpSeting() public static method

public static addIpSeting ( string mac, string DHCPEnable, string ipversion, string ip, string mask, string gateway ) : void
mac string
DHCPEnable string
ipversion string
ip string
mask string
gateway string
return void
Beispiel #1
0
        private void SetStaticIpv6Setting()
        {
            string macaddr = mac.value;

            resetError();

            if ((address6.Exists() && address6.value.Length != 0) || (gateway6.Exists() && gateway6.value.Length != 0))
            {
                bool FoundDevice = false;
                foreach (ManagementObject nic in WmiBase.Singleton.Win32_NetworkAdapterConfiguration)
                {
                    if (!(bool)nic["ipEnabled"])
                    {
                        continue;
                    }

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

                    FoundDevice = true;

                    IpSettings.addIpSeting(nic["macAddress"].ToString(), nic["DHCPEnabled"].ToString(), "IPV6", "", "", "");

                    try{
                        if (address6.Exists() && address6.value.Length != 0)
                        {
                            string argument = "interface ipv6 set address {0} {1}";
                            argument = string.Format(argument, nic["interfaceIndex"], address6.value);

                            if (netshInvoke(argument) != 0)
                            {
                                return;
                            }
                        }

                        if (gateway6.Exists() && gateway6.value.Length != 0)
                        {
                            string argument = "interface ipv6 add route ::/0 {0} {1}";
                            argument = string.Format(argument, nic["interfaceIndex"], gateway6.value);

                            if (netshInvoke(argument) != 0)
                            {
                                resetError();
                                argument = "interface ipv6 set route ::/0 {0} {1}";
                                argument = string.Format(argument, nic["interfaceIndex"], gateway6.value);

                                if (netshInvoke(argument) != 0)
                                {
                                    return;
                                }
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        errorCode.value = "1";
                        errorMsg.value  = e.ToString();

                        wmisession.Log("Exception " + e.ToString());
                        return;
                    }
                }
                if (!FoundDevice)
                {
                    errorCode.value = "101";
                    errorMsg.value  = "Device not ready to use or ipEnabled not been set";
                    wmisession.Log("Device not ready to use or ipEnabled not been set");
                    return;
                }
            }
        }
Beispiel #2
0
        private void SetStaticIpv4Setting()
        {
            string macaddr = mac.value;

            resetError();

            if ((address.Exists() && address.value.Length != 0) || (gateway.Exists() && gateway.value.Length != 0))
            {
                bool FoundDevice = false;
                foreach (ManagementObject nic in WmiBase.Singleton.Win32_NetworkAdapterConfiguration)
                {
                    if (!(bool)nic["ipEnabled"])
                    {
                        continue;
                    }

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

                    FoundDevice = true;

                    IpSettings.addIpSeting(nic["macAddress"].ToString(), nic["DHCPEnabled"].ToString(), "IPV4", "", "", "");

                    try{
                        if (address.Exists() && address.value.Length != 0)
                        {
                            string ipv4, netmask;
                            convertIpv4Mask(address.value, out ipv4, out netmask);

                            ManagementBaseObject objNewIP = nic.GetMethodParameters("EnableStatic");
                            objNewIP["IPAddress"]  = new string[] { ipv4 };
                            objNewIP["SubnetMask"] = new string[] { netmask };

                            if (setIpv4Network(nic, "EnableStatic", objNewIP, "ipv4 address setting") != 0)
                            {
                                return;
                            }
                        }

                        if (gateway.Exists() && gateway.value.Length != 0)
                        {
                            ManagementBaseObject objNewGate = nic.GetMethodParameters("SetGateways");
                            objNewGate["DefaultIPGateway"] = new string[] { gateway.value };

                            if (setIpv4Network(nic, "SetGateways", objNewGate, "ipv4 gateway setting") != 0)
                            {
                                return;
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        errorCode.value = "1";
                        errorMsg.value  = e.ToString();

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

                if (!FoundDevice)
                {
                    errorCode.value = "101";
                    errorMsg.value  = "Device not ready to use or ipEnabled not been set";
                    wmisession.Log("Device not ready to use or ipEnabled not been set");
                    return;
                }
            }
        }