Esempio n. 1
0
        public static int DhcpSetOptionValue(string server, DhcpOption Option)
        {
            DHCP_OPTION_SCOPE_INFO scopeInfo = new DHCP_OPTION_SCOPE_INFO();

            scopeInfo.ScopeType = DHCP_OPTION_SCOPE_TYPE.DhcpGlobalOptions;
            DHCP_OPTION convertedOption = new DHCP_OPTION();
            //convertedOption.
            int success = dhcpsapimethods.DhcpSetOptionValue(server, Option.OptionID, ref scopeInfo, ref convertedOption.DefaultValue);

            return(success);
        }
Esempio n. 2
0
 public static int DhcpCreateOption(string ipAddress, DhcpOption Option)
 {
     DHCP_OPTION convertedOption = new DHCP_OPTION();
     convertedOption.OptionType = Option.OptionType;
     convertedOption.OptionName = Option.OptionName;
     convertedOption.OptionID = Option.OptionID;
     convertedOption.OptionComment = Option.OptionComment;
     convertedOption.DefaultValue = ConvertToNative(Option);
     int success = dhcpsapimethods.DhcpCreateOption(ipAddress, convertedOption.OptionID, ref convertedOption);
     return success;
 }
Esempio n. 3
0
        public static int DhcpCreateOption(string ipAddress, DhcpOption Option)
        {
            DHCP_OPTION convertedOption = new DHCP_OPTION();

            convertedOption.OptionType    = Option.OptionType;
            convertedOption.OptionName    = Option.OptionName;
            convertedOption.OptionID      = Option.OptionID;
            convertedOption.OptionComment = Option.OptionComment;
            convertedOption.DefaultValue  = ConvertToNative(Option);
            int success = dhcpsapimethods.DhcpCreateOption(ipAddress, convertedOption.OptionID, ref convertedOption);

            return(success);
        }
Esempio n. 4
0
        static void Main(string[] args)
        {
            DhcpOption option = new DhcpOption();

            option.OptionID       = 82;
            option.OptionComment  = "test";
            option.OptionName     = "TestOption";
            option.IntData        = new uint[] { DhcpClient.StringToUint("172.22.249.213"), DhcpClient.StringToUint("172.22.249.214") };
            option.OptionType     = DHCP_OPTION_TYPE.DhcpArrayTypeOption;
            option.OptionDataType = DHCP_OPTION_DATA_TYPE.DhcpIpAddressOption;
            DhcpOption.DhcpCreateOption("192.168.2.246", option);


            //List<DhcpClient> clients = DhcpClient.DhcpEnumSubnetClients("192.168.2.246", "192.168.2.0");
            //foreach (DhcpClient client in clients)
            //{
            //    Console.WriteLine(client.ClientName);
            //    Console.WriteLine(client.ClientLeaseExpires);
            //    Console.WriteLine(client.ClientIpAddress);
            //    Console.WriteLine(client.ClientComment);
            //    Console.WriteLine(client.ClientHardwareAddress);
            //    Console.WriteLine(client.OwnerHost.HostName);
            //    Console.WriteLine(client.OwnerHost.IpAddress);
            //    Console.WriteLine(client.OwnerHost.NetBiosName);
            //    Console.WriteLine(client.SubnetMask);
            //    Console.ReadLine();
            //}



            DhcpClient dhcpClient = new DhcpClient();

            dhcpClient.ClientIpAddress       = "192.168.2.48";
            dhcpClient.SubnetMask            = "192.168.2.0";
            dhcpClient.ClientComment         = "this is a test";
            dhcpClient.ClientName            = "test1";
            dhcpClient.ClientHardwareAddress = "0800690201FC";
            dhcpClient.ClientLeaseExpires    = DateTime.Now.AddDays(30);
            dhcpClient.OwnerHost.HostName    = "MEAN-DEV";
            dhcpClient.OwnerHost.IpAddress   = "192.168.2.246";
            DhcpClient.DhcpCreateClientInfo("192.168.2.246", dhcpClient);
        }
Esempio n. 5
0
        static void Main(string[] args)
        {
            DhcpOption option = new DhcpOption();
            option.OptionID = 82;
            option.OptionComment = "test";
            option.OptionName = "TestOption";
            option.IntData = new uint[] { DhcpClient.StringToUint("172.22.249.213"), DhcpClient.StringToUint("172.22.249.214") };
            option.OptionType = DHCP_OPTION_TYPE.DhcpArrayTypeOption;
            option.OptionDataType = DHCP_OPTION_DATA_TYPE.DhcpIpAddressOption;
            DhcpOption.DhcpCreateOption("192.168.2.246", option);

            //List<DhcpClient> clients = DhcpClient.DhcpEnumSubnetClients("192.168.2.246", "192.168.2.0");
            //foreach (DhcpClient client in clients)
            //{
            //    Console.WriteLine(client.ClientName);
            //    Console.WriteLine(client.ClientLeaseExpires);
            //    Console.WriteLine(client.ClientIpAddress);
            //    Console.WriteLine(client.ClientComment);
            //    Console.WriteLine(client.ClientHardwareAddress);
            //    Console.WriteLine(client.OwnerHost.HostName);
            //    Console.WriteLine(client.OwnerHost.IpAddress);
            //    Console.WriteLine(client.OwnerHost.NetBiosName);
            //    Console.WriteLine(client.SubnetMask);
            //    Console.ReadLine();
            //}

            DhcpClient dhcpClient = new DhcpClient();
            dhcpClient.ClientIpAddress = "192.168.2.48";
            dhcpClient.SubnetMask = "192.168.2.0";
            dhcpClient.ClientComment = "this is a test";
            dhcpClient.ClientName = "test1";
            dhcpClient.ClientHardwareAddress = "0800690201FC";
            dhcpClient.ClientLeaseExpires = DateTime.Now.AddDays(30);
            dhcpClient.OwnerHost.HostName = "MEAN-DEV";
            dhcpClient.OwnerHost.IpAddress = "192.168.2.246";
            DhcpClient.DhcpCreateClientInfo("192.168.2.246", dhcpClient);
        }
Esempio n. 6
0
        private static DHCP_OPTION_DATA ConvertToNative(DhcpOption Option)
        {
            DHCP_OPTION_DATA_ELEMENT dataElement = new DHCP_OPTION_DATA_ELEMENT();
            DHCP_OPTION_DATA         data        = new DHCP_OPTION_DATA();
            IntPtr dataPtr;

            if (Option.OptionDataType == DHCP_OPTION_DATA_TYPE.DhcpStringDataOption)
            {
                data.NumElements = Option.StringData.Length;
                data.Elements    = Marshal.AllocHGlobal(Option.StringData.Length);
                for (int i = 0; i < data.NumElements; i++)
                {
                    dataElement.OptionType       = DHCP_OPTION_DATA_TYPE.DhcpStringDataOption;
                    dataElement.StringDataOption = Marshal.StringToBSTR(Option.StringData[i]);
                    dataPtr = (IntPtr)(data.Elements.ToInt32()) + (i * Marshal.SizeOf(typeof(DHCP_OPTION_DATA_ELEMENT)));
                    Marshal.StructureToPtr(dataElement, dataPtr, false);
                }
                return(data);
            }
            else if (Option.OptionDataType == DHCP_OPTION_DATA_TYPE.DhcpByteOption)
            {
                data.NumElements = Option.ByteData.Length;
                data.Elements    = Marshal.AllocHGlobal(Option.ByteData.Length);
                for (int i = 0; i < data.NumElements; i++)
                {
                    dataElement.OptionType       = DHCP_OPTION_DATA_TYPE.DhcpStringDataOption;
                    dataElement.StringDataOption = Marshal.StringToBSTR(Option.StringData[i]);
                    dataPtr = (IntPtr)(data.Elements.ToInt32()) + (i * Marshal.SizeOf(typeof(DHCP_OPTION_DATA_ELEMENT)));
                    Marshal.StructureToPtr(dataElement, dataPtr, false);
                }
                return(data);
            }
            else if (Option.OptionDataType == DHCP_OPTION_DATA_TYPE.DhcpDWordDWordOption)
            {
                data.NumElements = Option.StringData.Length;
                data.Elements    = Marshal.AllocHGlobal(Option.StringData.Length);
                for (int i = 0; i < data.NumElements; i++)
                {
                    dataElement.OptionType       = DHCP_OPTION_DATA_TYPE.DhcpStringDataOption;
                    dataElement.StringDataOption = Marshal.StringToBSTR(Option.StringData[i]);
                    dataPtr = (IntPtr)(data.Elements.ToInt32()) + (i * Marshal.SizeOf(typeof(DHCP_OPTION_DATA_ELEMENT)));
                    Marshal.StructureToPtr(dataElement, dataPtr, false);
                }
                return(data);
            }
            else if (Option.OptionDataType == DHCP_OPTION_DATA_TYPE.DhcpDWordOption)
            {
                data.NumElements = Option.StringData.Length;
                data.Elements    = Marshal.AllocHGlobal(Option.StringData.Length);
                for (int i = 0; i < data.NumElements; i++)
                {
                    dataElement.OptionType       = DHCP_OPTION_DATA_TYPE.DhcpStringDataOption;
                    dataElement.StringDataOption = Marshal.StringToBSTR(Option.StringData[i]);
                    dataPtr = (IntPtr)(data.Elements.ToInt32()) + (i * Marshal.SizeOf(typeof(DHCP_OPTION_DATA_ELEMENT)));
                    Marshal.StructureToPtr(dataElement, dataPtr, false);
                }
                return(data);
            }
            else if (Option.OptionDataType == DHCP_OPTION_DATA_TYPE.DhcpEncapsulatedDataOption)
            {
                data.NumElements = Option.StringData.Length;
                data.Elements    = Marshal.AllocHGlobal(Option.StringData.Length);
                for (int i = 0; i < data.NumElements; i++)
                {
                    dataElement.OptionType       = DHCP_OPTION_DATA_TYPE.DhcpStringDataOption;
                    dataElement.StringDataOption = Marshal.StringToBSTR(Option.StringData[i]);
                    dataPtr = (IntPtr)(data.Elements.ToInt32()) + (i * Marshal.SizeOf(typeof(DHCP_OPTION_DATA_ELEMENT)));
                    Marshal.StructureToPtr(dataElement, dataPtr, false);
                }
                return(data);
            }
            else if (Option.OptionDataType == DHCP_OPTION_DATA_TYPE.DhcpIpAddressOption)
            {
                data.NumElements = Option.IntData.Length;
                data.Elements    = Marshal.AllocHGlobal(Option.IntData.Length);
                for (int i = 0; i < data.NumElements; i++)
                {
                    dataElement.OptionType      = DHCP_OPTION_DATA_TYPE.DhcpIpAddressOption;
                    dataElement.IpAddressOption = Option.IntData[i];
                    dataPtr = (IntPtr)(data.Elements.ToInt32()) + (i * Marshal.SizeOf(typeof(DHCP_OPTION_DATA_ELEMENT)));
                    Marshal.StructureToPtr(dataElement, dataPtr, false);
                }
                return(data);
            }
            else if (Option.OptionDataType == DHCP_OPTION_DATA_TYPE.DhcpIpv6AddressOption)
            {
                data.NumElements = Option.StringData.Length;
                data.Elements    = Marshal.AllocHGlobal(Option.StringData.Length);
                for (int i = 0; i < data.NumElements; i++)
                {
                    dataElement.OptionType       = DHCP_OPTION_DATA_TYPE.DhcpStringDataOption;
                    dataElement.StringDataOption = Marshal.StringToBSTR(Option.StringData[i]);
                    dataPtr = (IntPtr)(data.Elements.ToInt32()) + (i * Marshal.SizeOf(typeof(DHCP_OPTION_DATA_ELEMENT)));
                    Marshal.StructureToPtr(dataElement, dataPtr, false);
                }
                return(data);
            }
            else if (Option.OptionDataType == DHCP_OPTION_DATA_TYPE.DhcpWordOption)
            {
                data.NumElements = Option.StringData.Length;
                data.Elements    = Marshal.AllocHGlobal(Option.StringData.Length);
                for (int i = 0; i < data.NumElements; i++)
                {
                    dataElement.OptionType       = DHCP_OPTION_DATA_TYPE.DhcpStringDataOption;
                    dataElement.StringDataOption = Marshal.StringToBSTR(Option.StringData[i]);
                    dataPtr = (IntPtr)(data.Elements.ToInt32()) + (i * Marshal.SizeOf(typeof(DHCP_OPTION_DATA_ELEMENT)));
                    Marshal.StructureToPtr(dataElement, dataPtr, false);
                }
                return(data);
            }
            return(data);
        }
Esempio n. 7
0
 public static int DhcpSetOptionValue(string server, DhcpOption Option)
 {
     DHCP_OPTION_SCOPE_INFO scopeInfo = new DHCP_OPTION_SCOPE_INFO();
     scopeInfo.ScopeType = DHCP_OPTION_SCOPE_TYPE.DhcpGlobalOptions;
     DHCP_OPTION convertedOption = new DHCP_OPTION();
     //convertedOption.
     int success = dhcpsapimethods.DhcpSetOptionValue(server, Option.OptionID, ref scopeInfo, ref convertedOption.DefaultValue);
     return success;
 }
Esempio n. 8
0
 private static DHCP_OPTION_DATA ConvertToNative(DhcpOption Option)
 {
     DHCP_OPTION_DATA_ELEMENT dataElement = new DHCP_OPTION_DATA_ELEMENT();
     DHCP_OPTION_DATA data = new DHCP_OPTION_DATA();
     IntPtr dataPtr;
     if (Option.OptionDataType == DHCP_OPTION_DATA_TYPE.DhcpStringDataOption) {
         data.NumElements = Option.StringData.Length;
         data.Elements = Marshal.AllocHGlobal(Option.StringData.Length);
         for (int i = 0; i < data.NumElements; i++) {
             dataElement.OptionType = DHCP_OPTION_DATA_TYPE.DhcpStringDataOption;
             dataElement.StringDataOption = Marshal.StringToBSTR(Option.StringData[i]);
             dataPtr = (IntPtr)(data.Elements.ToInt32()) + (i * Marshal.SizeOf(typeof(DHCP_OPTION_DATA_ELEMENT)));
             Marshal.StructureToPtr(dataElement, dataPtr, false);
         }
         return data;
     } else if (Option.OptionDataType == DHCP_OPTION_DATA_TYPE.DhcpByteOption) {
         data.NumElements = Option.ByteData.Length;
         data.Elements = Marshal.AllocHGlobal(Option.ByteData.Length);
         for (int i = 0; i < data.NumElements; i++) {
             dataElement.OptionType = DHCP_OPTION_DATA_TYPE.DhcpStringDataOption;
             dataElement.StringDataOption = Marshal.StringToBSTR(Option.StringData[i]);
             dataPtr = (IntPtr)(data.Elements.ToInt32()) + (i * Marshal.SizeOf(typeof(DHCP_OPTION_DATA_ELEMENT)));
             Marshal.StructureToPtr(dataElement, dataPtr, false);
         }
         return data;
     } else if (Option.OptionDataType == DHCP_OPTION_DATA_TYPE.DhcpDWordDWordOption) {
         data.NumElements = Option.StringData.Length;
         data.Elements = Marshal.AllocHGlobal(Option.StringData.Length);
         for (int i = 0; i < data.NumElements; i++) {
             dataElement.OptionType = DHCP_OPTION_DATA_TYPE.DhcpStringDataOption;
             dataElement.StringDataOption = Marshal.StringToBSTR(Option.StringData[i]);
             dataPtr = (IntPtr)(data.Elements.ToInt32()) + (i * Marshal.SizeOf(typeof(DHCP_OPTION_DATA_ELEMENT)));
             Marshal.StructureToPtr(dataElement, dataPtr, false);
         }
         return data;
     } else if (Option.OptionDataType == DHCP_OPTION_DATA_TYPE.DhcpDWordOption) {
         data.NumElements = Option.StringData.Length;
         data.Elements = Marshal.AllocHGlobal(Option.StringData.Length);
         for (int i = 0; i < data.NumElements; i++) {
             dataElement.OptionType = DHCP_OPTION_DATA_TYPE.DhcpStringDataOption;
             dataElement.StringDataOption = Marshal.StringToBSTR(Option.StringData[i]);
             dataPtr = (IntPtr)(data.Elements.ToInt32()) + (i * Marshal.SizeOf(typeof(DHCP_OPTION_DATA_ELEMENT)));
             Marshal.StructureToPtr(dataElement, dataPtr, false);
         }
         return data;
     } else if (Option.OptionDataType == DHCP_OPTION_DATA_TYPE.DhcpEncapsulatedDataOption) {
         data.NumElements = Option.StringData.Length;
         data.Elements = Marshal.AllocHGlobal(Option.StringData.Length);
         for (int i = 0; i < data.NumElements; i++) {
             dataElement.OptionType = DHCP_OPTION_DATA_TYPE.DhcpStringDataOption;
             dataElement.StringDataOption = Marshal.StringToBSTR(Option.StringData[i]);
             dataPtr = (IntPtr)(data.Elements.ToInt32()) + (i * Marshal.SizeOf(typeof(DHCP_OPTION_DATA_ELEMENT)));
             Marshal.StructureToPtr(dataElement, dataPtr, false);
         }
         return data;
     } else if (Option.OptionDataType == DHCP_OPTION_DATA_TYPE.DhcpIpAddressOption) {
         data.NumElements = Option.IntData.Length;
         data.Elements = Marshal.AllocHGlobal(Option.IntData.Length);
         for (int i = 0; i < data.NumElements; i++) {
             dataElement.OptionType = DHCP_OPTION_DATA_TYPE.DhcpIpAddressOption;
             dataElement.IpAddressOption = Option.IntData[i];
             dataPtr = (IntPtr)(data.Elements.ToInt32()) + (i * Marshal.SizeOf(typeof(DHCP_OPTION_DATA_ELEMENT)));
             Marshal.StructureToPtr(dataElement, dataPtr, false);
         }
         return data;
     } else if (Option.OptionDataType == DHCP_OPTION_DATA_TYPE.DhcpIpv6AddressOption) {
         data.NumElements = Option.StringData.Length;
         data.Elements = Marshal.AllocHGlobal(Option.StringData.Length);
         for (int i = 0; i < data.NumElements; i++) {
             dataElement.OptionType = DHCP_OPTION_DATA_TYPE.DhcpStringDataOption;
             dataElement.StringDataOption = Marshal.StringToBSTR(Option.StringData[i]);
             dataPtr = (IntPtr)(data.Elements.ToInt32()) + (i * Marshal.SizeOf(typeof(DHCP_OPTION_DATA_ELEMENT)));
             Marshal.StructureToPtr(dataElement, dataPtr, false);
         }
         return data;
     } else if (Option.OptionDataType == DHCP_OPTION_DATA_TYPE.DhcpWordOption) {
         data.NumElements = Option.StringData.Length;
         data.Elements = Marshal.AllocHGlobal(Option.StringData.Length);
         for (int i = 0; i < data.NumElements; i++) {
             dataElement.OptionType = DHCP_OPTION_DATA_TYPE.DhcpStringDataOption;
             dataElement.StringDataOption = Marshal.StringToBSTR(Option.StringData[i]);
             dataPtr = (IntPtr)(data.Elements.ToInt32()) + (i * Marshal.SizeOf(typeof(DHCP_OPTION_DATA_ELEMENT)));
             Marshal.StructureToPtr(dataElement, dataPtr, false);
         }
         return data;
     }
     return data;
 }