jpmikkers / dhcpserver Goto Github PK
View Code? Open in Web Editor NEWManaged DHCP server implementation, written in C#
License: MIT License
Managed DHCP server implementation, written in C#
License: MIT License
Hi, we are evaluating your library and it works very well. We do have a question however. It seems that our windows devices are sending option 50 and the dhcp server is respecting it. We have removed the reference to option 50 in the dhcp message but that is causing other issues.
Line 208 In DHCPMessage.cs
//optionsTemplates[(int)TDHCPOption.RequestedIPAddress] = new DHCPOptionRequestedIPAddress();
Basically you can replicate like this:
We want to not allow this requestedIPAddress and force the client to get a new IP in the range of .100-125, or just in general ALWAYS force a new ip to the client requesting.
Hi JP,
here use your code on linux for iPXE Boot,has failed as below, i know your code run sucsess on windows, for linux can you give some advice?
many thanks.~
DHCP Server start failed, reason 'System.PlatformNotSupportedException: Socket.IOControl handles Windows-specific control codes and is not supported on this platform.
at System.Net.Sockets.SocketPal.WindowsIoctl(SafeSocketHandle handle, Int32 ioControlCode, Byte[] optionInValue, Byte[] optionOutValue, Int32& optionLength)
at System.Net.Sockets.Socket.IOControl(Int32 ioControlCode, Byte[] optionInValue, Byte[] optionOutValue)
at System.Net.Sockets.Socket.IOControl(IOControlCode ioControlCode, Byte[] optionInValue, Byte[] optionOutValue)
at GitHub.JPMikkers.DHCP.UDPSocket..ctor(IPEndPoint localEndPoint, Int32 packetSize, Boolean dontFragment, Int16 ttl, OnReceiveDelegate onReceive, OnStopDelegate onStop) in /home/jingxi/Code/autostress/Library/UDPSocket.cs:line 139
Support option 82 (DHCP Relay Agent Information) for reserved address/pool assignment.
This will enable port/switch based IP address assignment.
See:
https://tools.ietf.org/html/rfc3046#page-6
https://www.juniper.net/documentation/en_US/junose15.1/topics/concept/dhcp-relay-option-82-suboptions-overview.html
http://www.firewall.cx/cisco-technical-knowledgebase/cisco-switches/1218-dhcp-snooping-option-82-relay-agent-message-format-analysis.html
it seems that the registered DHCP server service depends running folder path. and can't uninstall or reinstall service.
Hi JP,
Sorry for a long post, I have been using TinyPXE to chainload iPXE to install OS.
How do I chainload ipxe? In the configuration.xml, how do I specify an alternate file name or user-class i.e. winpe4.ipxe after downloading ipxe.pxe? My TFTP IP is the same as DHCP. Please see my config below. It downloads ipxe.pxe without a problem but it does not chainload the winpe file. I'm also testing with your TFTP server.
?xml version="1.0"?> <ArrayOfDHCPServerConfiguration xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <DHCPServerConfiguration> <Name>DHCP</Name> <Address>10.0.0.1</Address> <NetMask>255.255.255.0</NetMask> <PoolStart>10.0.0.50</PoolStart> <PoolEnd>10.0.0.200</PoolEnd> <LeaseTime>86400</LeaseTime> <OfferTime>30</OfferTime> <MinimumPacketSize>576</MinimumPacketSize> <Options> <OptionConfiguration xsi:type="OptionConfigurationTFTPServerName"> <Mode>Default</Mode> <ZeroTerminatedStrings>true</ZeroTerminatedStrings> <Name>10.0.0.1</Name> </OptionConfiguration> <OptionConfiguration xsi:type="OptionConfigurationBootFileName"> <Mode>Default</Mode> <ZeroTerminatedStrings>true</ZeroTerminatedStrings> <Name>ipxe.pxe</Name> </OptionConfiguration> <OptionConfiguration xsi:type="OptionConfigurationTFTPServerName"> <Mode>Default</Mode> <ZeroTerminatedStrings>true</ZeroTerminatedStrings> <Name>10.0.0.1</Name> </OptionConfiguration> <OptionConfiguration xsi:type="OptionConfigurationBootFileName"> <Mode>Default</Mode> <ZeroTerminatedStrings>true</ZeroTerminatedStrings> <Name>winpe4.ipxe</Name> </OptionConfiguration> </Options> </DHCPServerConfiguration> </ArrayOfDHCPServerConfiguration>
In the DHCP Log, the Next Server Address is 0.0.0.0. How do I set this up?
2019-07-12 11:04:55.000 : INFO : DHCP : Incoming packet - parsing DHCP Message
2019-07-12 11:04:55.000 : INFO : DHCP : c->s Opcode (op) : BootRequest
c->s HardwareType (htype) : Ethernet
c->s Hops : 0
c->s XID : 677712405
c->s Secs : 4
c->s BroadCast (flags) : True
c->s ClientIPAddress (ciaddr) : 0.0.0.0
c->s YourIPAddress (yiaddr) : 0.0.0.0
c->s NextServerIPAddress (siaddr) : 0.0.0.0
c->s RelayAgentIPAddress (giaddr) : 0.0.0.0
c->s ClientHardwareAddress (chaddr) : 08-00-27-65-12-15
c->s ServerHostName (sname) :
c->s BootFileName (file) :
c->s Option : Option(name=[MessageType],value=[DISCOVER])
c->s Option : Option(name=[ParameterRequestList],value=[SubnetMask,TimeOffset,Router,TimeServer,NameServer,DomainNameServer,ResourceLocationServer,HostName,BootFileSize,DomainName,SwapServer,RootPath,ExtensionPath,MaximumDatagramReassembly,DefaultIPTTL,BroadcastAddress,NetworkInformationServiceDomain,NetworkInformationServiceServers,NetworkTimeProtocolServers,VendorSpecificInformation,RequestedIPAddress,IPAddressLeaseTime,ServerIdentifier,RenewalTimeValue,RebindingTimeValue,VendorClassIdentifier,TFTPServerName,BootFileName,128,129,130,131,132,133,134,135])
c->s Option : Option(name=[MaximumDHCPMessageSize],value=[1260])
c->s Option : Option(name=[ClientMachineIdentifier],value=[00 27 F6 86 73 0A BE 4A 8D 8A 38 D9 9B 16 BA D1 2A])
c->s Option : Option(name=[ClientSystemArchitectureType],value=[00 00])
c->s Option : Option(name=[ClientNetworkInterfaceIdentifier],value=[01 02 01])
c->s Option : Option(name=[VendorClassIdentifier],value=[50 58 45 43 6C 69 65 6E 74 3A 41 72 63 68 3A 30 30 30 30 30 3A 55 4E 44 49 3A 30 30 32 30 30 31])
2019-07-12 11:04:55.000 : INFO : DHCP : Client 08-00-27-65-12-15 () sent DISCOVER
2019-07-12 11:04:55.000 : INFO : DHCP : Client is known, in state Assigned
2019-07-12 11:04:55.000 : INFO : DHCP : Client sent DISCOVER but we already offered, or assigned -> repeat offer with known address
2019-07-12 11:04:55.000 : INFO : DHCP : ==== Sending response to 255.255.255.255:68 ====
2019-07-12 11:04:55.000 : INFO : DHCP : s->c Opcode (op) : BootReply
s->c HardwareType (htype) : Ethernet
s->c Hops : 0
s->c XID : 677712405
s->c Secs : 0
s->c BroadCast (flags) : True
s->c ClientIPAddress (ciaddr) : 0.0.0.0
s->c YourIPAddress (yiaddr) : 10.0.0.50
s->c NextServerIPAddress (siaddr) : 0.0.0.0
s->c RelayAgentIPAddress (giaddr) : 0.0.0.0
s->c ClientHardwareAddress (chaddr) : 08-00-27-65-12-15
s->c ServerHostName (sname) :
s->c BootFileName (file) :
s->c Option : Option(name=[MessageType],value=[OFFER])
s->c Option : Option(name=[IPAddressLeaseTime],value=[1.00:00:00])
s->c Option : Option(name=[ServerIdentifier],value=[10.0.0.1])
s->c Option : Option(name=[SubnetMask],value=[255.255.255.0])
s->c Option : Option(name=[TFTPServerName],value=[10.0.0.1])
s->c Option : Option(name=[BootFileName],value=[ipxe.pxe])
2019-07-12 11:04:57.000 : INFO : DHCP : Incoming packet - parsing DHCP Message
2019-07-12 11:04:57.000 : INFO : DHCP : c->s Opcode (op) : BootRequest
c->s HardwareType (htype) : Ethernet
c->s Hops : 0
c->s XID : 677712405
c->s Secs : 4
c->s BroadCast (flags) : True
c->s ClientIPAddress (ciaddr) : 0.0.0.0
c->s YourIPAddress (yiaddr) : 0.0.0.0
c->s NextServerIPAddress (siaddr) : 0.0.0.0
c->s RelayAgentIPAddress (giaddr) : 0.0.0.0
c->s ClientHardwareAddress (chaddr) : 08-00-27-65-12-15
c->s ServerHostName (sname) :
c->s BootFileName (file) :
c->s Option : Option(name=[MessageType],value=[REQUEST])
c->s Option : Option(name=[RequestedIPAddress],value=[10.0.0.50])
c->s Option : Option(name=[ParameterRequestList],value=[SubnetMask,TimeOffset,Router,TimeServer,NameServer,DomainNameServer,ResourceLocationServer,HostName,BootFileSize,DomainName,SwapServer,RootPath,ExtensionPath,MaximumDatagramReassembly,DefaultIPTTL,BroadcastAddress,NetworkInformationServiceDomain,NetworkInformationServiceServers,NetworkTimeProtocolServers,VendorSpecificInformation,RequestedIPAddress,IPAddressLeaseTime,ServerIdentifier,RenewalTimeValue,RebindingTimeValue,VendorClassIdentifier,TFTPServerName,BootFileName,128,129,130,131,132,133,134,135])
c->s Option : Option(name=[MaximumDHCPMessageSize],value=[1260])
c->s Option : Option(name=[ServerIdentifier],value=[10.0.0.1])
c->s Option : Option(name=[ClientMachineIdentifier],value=[00 27 F6 86 73 0A BE 4A 8D 8A 38 D9 9B 16 BA D1 2A])
c->s Option : Option(name=[ClientSystemArchitectureType],value=[00 00])
c->s Option : Option(name=[ClientNetworkInterfaceIdentifier],value=[01 02 01])
c->s Option : Option(name=[VendorClassIdentifier],value=[50 58 45 43 6C 69 65 6E 74 3A 41 72 63 68 3A 30 30 30 30 30 3A 55 4E 44 49 3A 30 30 32 30 30 31])
2019-07-12 11:04:57.000 : INFO : DHCP : Client 08-00-27-65-12-15 () sent REQUEST
2019-07-12 11:04:57.000 : INFO : DHCP : Client request matches offered address -> ACK
2019-07-12 11:04:57.000 : INFO : DHCP : ==== Sending response to 255.255.255.255:68 ====
2019-07-12 11:04:57.000 : INFO : DHCP : s->c Opcode (op) : BootReply
s->c HardwareType (htype) : Ethernet
s->c Hops : 0
s->c XID : 677712405
s->c Secs : 0
s->c BroadCast (flags) : True
s->c ClientIPAddress (ciaddr) : 0.0.0.0
s->c YourIPAddress (yiaddr) : 10.0.0.50
s->c NextServerIPAddress (siaddr) : 0.0.0.0
s->c RelayAgentIPAddress (giaddr) : 0.0.0.0
s->c ClientHardwareAddress (chaddr) : 08-00-27-65-12-15
s->c ServerHostName (sname) :
s->c BootFileName (file) :
s->c Option : Option(name=[MessageType],value=[ACK])
s->c Option : Option(name=[IPAddressLeaseTime],value=[1.00:00:00])
s->c Option : Option(name=[ServerIdentifier],value=[10.0.0.1])
s->c Option : Option(name=[SubnetMask],value=[255.255.255.0])
s->c Option : Option(name=[TFTPServerName],value=[10.0.0.1])
s->c Option : Option(name=[BootFileName],value=[ipxe.pxe])
2019-07-12 11:05:01.000 : INFO : DHCP : Incoming packet - parsing DHCP Message
2019-07-12 11:05:01.000 : INFO : DHCP : c->s Opcode (op) : BootRequest
c->s HardwareType (htype) : Ethernet
c->s Hops : 0
c->s XID : 3801050661
c->s Secs : 4
c->s BroadCast (flags) : True
c->s ClientIPAddress (ciaddr) : 0.0.0.0
c->s YourIPAddress (yiaddr) : 0.0.0.0
c->s NextServerIPAddress (siaddr) : 0.0.0.0
c->s RelayAgentIPAddress (giaddr) : 0.0.0.0
c->s ClientHardwareAddress (chaddr) : 08-00-27-65-12-15
c->s ServerHostName (sname) :
c->s BootFileName (file) :
c->s Option : Option(name=[MessageType],value=[DISCOVER])
c->s Option : Option(name=[MaximumDHCPMessageSize],value=[1472])
c->s Option : Option(name=[ClientSystemArchitectureType],value=[00 00])
c->s Option : Option(name=[ClientNetworkInterfaceIdentifier],value=[01 02 01])
c->s Option : Option(name=[VendorClassIdentifier],value=[50 58 45 43 6C 69 65 6E 74 3A 41 72 63 68 3A 30 30 30 30 30 3A 55 4E 44 49 3A 30 30 32 30 30 31])
c->s Option : Option(name=[77],value=[69 50 58 45])
c->s Option : Option(name=[ParameterRequestList],value=[SubnetMask,Router,DomainNameServer,LogServer,HostName,DomainName,RootPath,InterfaceMTU,VendorSpecificInformation,VendorClassIdentifier,TFTPServerName,BootFileName,119,128,129,130,131,132,133,134,135,175,203])
c->s Option : Option(name=[175],value=[B1 05 01 80 86 10 0E EB 03 01 00 00 17 01 01 22 01 01 16 01 01 13 01 01 14 01 01 11 01 01 27 01 01 19 01 01 29 01 01 10 01 02 21 01 01 15 01 01 18 01 01 23 01 01 1B 01 01 26 01 01 12 01 01])
c->s Option : Option(name=[ClientIdentifier],htype=[Unknown],value=[08 00 27 65 12 15])
c->s Option : Option(name=[ClientMachineIdentifier],value=[00 73 86 F6 27 BE 0A 8D 4A 8A 38 D9 9B 16 BA D1 2A])
2019-07-12 11:05:01.000 : INFO : DHCP : Client 08-00-27-65-12-15 () sent DISCOVER
2019-07-12 11:05:01.000 : INFO : DHCP : Client is known, in state Assigned
2019-07-12 11:05:01.000 : INFO : DHCP : Client sent DISCOVER but we already offered, or assigned -> repeat offer with known address
2019-07-12 11:05:01.000 : INFO : DHCP : ==== Sending response to 255.255.255.255:68 ====
2019-07-12 11:05:01.000 : INFO : DHCP : s->c Opcode (op) : BootReply
s->c HardwareType (htype) : Ethernet
s->c Hops : 0
s->c XID : 3801050661
s->c Secs : 0
s->c BroadCast (flags) : True
s->c ClientIPAddress (ciaddr) : 0.0.0.0
s->c YourIPAddress (yiaddr) : 10.0.0.50
s->c NextServerIPAddress (siaddr) : 0.0.0.0
s->c RelayAgentIPAddress (giaddr) : 0.0.0.0
s->c ClientHardwareAddress (chaddr) : 08-00-27-65-12-15
s->c ServerHostName (sname) :
s->c BootFileName (file) :
s->c Option : Option(name=[MessageType],value=[OFFER])
s->c Option : Option(name=[IPAddressLeaseTime],value=[1.00:00:00])
s->c Option : Option(name=[ServerIdentifier],value=[10.0.0.1])
s->c Option : Option(name=[SubnetMask],value=[255.255.255.0])
s->c Option : Option(name=[TFTPServerName],value=[10.0.0.1])
s->c Option : Option(name=[BootFileName],value=[ipxe.pxe])
2019-07-12 11:05:02.000 : INFO : DHCP : Incoming packet - parsing DHCP Message
2019-07-12 11:05:02.000 : INFO : DHCP : c->s Opcode (op) : BootRequest
c->s HardwareType (htype) : Ethernet
c->s Hops : 0
c->s XID : 3801050661
c->s Secs : 10
c->s BroadCast (flags) : True
c->s ClientIPAddress (ciaddr) : 0.0.0.0
c->s YourIPAddress (yiaddr) : 0.0.0.0
c->s NextServerIPAddress (siaddr) : 0.0.0.0
c->s RelayAgentIPAddress (giaddr) : 0.0.0.0
c->s ClientHardwareAddress (chaddr) : 08-00-27-65-12-15
c->s ServerHostName (sname) :
c->s BootFileName (file) :
c->s Option : Option(name=[MessageType],value=[DISCOVER])
c->s Option : Option(name=[MaximumDHCPMessageSize],value=[1472])
c->s Option : Option(name=[ClientSystemArchitectureType],value=[00 00])
c->s Option : Option(name=[ClientNetworkInterfaceIdentifier],value=[01 02 01])
c->s Option : Option(name=[VendorClassIdentifier],value=[50 58 45 43 6C 69 65 6E 74 3A 41 72 63 68 3A 30 30 30 30 30 3A 55 4E 44 49 3A 30 30 32 30 30 31])
c->s Option : Option(name=[77],value=[69 50 58 45])
c->s Option : Option(name=[ParameterRequestList],value=[SubnetMask,Router,DomainNameServer,LogServer,HostName,DomainName,RootPath,InterfaceMTU,VendorSpecificInformation,VendorClassIdentifier,TFTPServerName,BootFileName,119,128,129,130,131,132,133,134,135,175,203])
c->s Option : Option(name=[175],value=[B1 05 01 80 86 10 0E EB 03 01 00 00 17 01 01 22 01 01 16 01 01 13 01 01 14 01 01 11 01 01 27 01 01 19 01 01 29 01 01 10 01 02 21 01 01 15 01 01 18 01 01 23 01 01 1B 01 01 26 01 01 12 01 01])
c->s Option : Option(name=[ClientIdentifier],htype=[Unknown],value=[08 00 27 65 12 15])
c->s Option : Option(name=[ClientMachineIdentifier],value=[00 73 86 F6 27 BE 0A 8D 4A 8A 38 D9 9B 16 BA D1 2A])
2019-07-12 11:05:02.000 : INFO : DHCP : Client 08-00-27-65-12-15 () sent DISCOVER
2019-07-12 11:05:02.000 : INFO : DHCP : Client is known, in state Offered
2019-07-12 11:05:02.000 : INFO : DHCP : Client sent DISCOVER but we already offered, or assigned -> repeat offer with known address
2019-07-12 11:05:02.000 : INFO : DHCP : ==== Sending response to 255.255.255.255:68 ====
2019-07-12 11:05:02.000 : INFO : DHCP : s->c Opcode (op) : BootReply
s->c HardwareType (htype) : Ethernet
s->c Hops : 0
s->c XID : 3801050661
s->c Secs : 0
s->c BroadCast (flags) : True
s->c ClientIPAddress (ciaddr) : 0.0.0.0
s->c YourIPAddress (yiaddr) : 10.0.0.50
s->c NextServerIPAddress (siaddr) : 0.0.0.0
s->c RelayAgentIPAddress (giaddr) : 0.0.0.0
s->c ClientHardwareAddress (chaddr) : 08-00-27-65-12-15
s->c ServerHostName (sname) :
s->c BootFileName (file) :
s->c Option : Option(name=[MessageType],value=[OFFER])
s->c Option : Option(name=[IPAddressLeaseTime],value=[1.00:00:00])
s->c Option : Option(name=[ServerIdentifier],value=[10.0.0.1])
s->c Option : Option(name=[SubnetMask],value=[255.255.255.0])
s->c Option : Option(name=[TFTPServerName],value=[10.0.0.1])
s->c Option : Option(name=[BootFileName],value=[ipxe.pxe])
2019-07-12 11:05:04.000 : INFO : DHCP : Incoming packet - parsing DHCP Message
2019-07-12 11:05:04.000 : INFO : DHCP : c->s Opcode (op) : BootRequest
c->s HardwareType (htype) : Ethernet
c->s Hops : 0
c->s XID : 3801050661
c->s Secs : 18
c->s BroadCast (flags) : True
c->s ClientIPAddress (ciaddr) : 0.0.0.0
c->s YourIPAddress (yiaddr) : 0.0.0.0
c->s NextServerIPAddress (siaddr) : 0.0.0.0
c->s RelayAgentIPAddress (giaddr) : 0.0.0.0
c->s ClientHardwareAddress (chaddr) : 08-00-27-65-12-15
c->s ServerHostName (sname) :
c->s BootFileName (file) :
c->s Option : Option(name=[MessageType],value=[REQUEST])
c->s Option : Option(name=[MaximumDHCPMessageSize],value=[1472])
c->s Option : Option(name=[ClientSystemArchitectureType],value=[00 00])
c->s Option : Option(name=[ClientNetworkInterfaceIdentifier],value=[01 02 01])
c->s Option : Option(name=[VendorClassIdentifier],value=[50 58 45 43 6C 69 65 6E 74 3A 41 72 63 68 3A 30 30 30 30 30 3A 55 4E 44 49 3A 30 30 32 30 30 31])
c->s Option : Option(name=[77],value=[69 50 58 45])
c->s Option : Option(name=[ParameterRequestList],value=[SubnetMask,Router,DomainNameServer,LogServer,HostName,DomainName,RootPath,InterfaceMTU,VendorSpecificInformation,VendorClassIdentifier,TFTPServerName,BootFileName,119,128,129,130,131,132,133,134,135,175,203])
c->s Option : Option(name=[175],value=[B1 05 01 80 86 10 0E EB 03 01 00 00 17 01 01 22 01 01 16 01 01 13 01 01 14 01 01 11 01 01 27 01 01 19 01 01 29 01 01 10 01 02 21 01 01 15 01 01 18 01 01 23 01 01 1B 01 01 26 01 01 12 01 01])
c->s Option : Option(name=[ClientIdentifier],htype=[Unknown],value=[08 00 27 65 12 15])
c->s Option : Option(name=[ClientMachineIdentifier],value=[00 73 86 F6 27 BE 0A 8D 4A 8A 38 D9 9B 16 BA D1 2A])
c->s Option : Option(name=[ServerIdentifier],value=[10.0.0.1])
c->s Option : Option(name=[RequestedIPAddress],value=[10.0.0.50])
2019-07-12 11:05:04.000 : INFO : DHCP : Client 08-00-27-65-12-15 () sent REQUEST
2019-07-12 11:05:04.000 : INFO : DHCP : Client request matches offered address -> ACK
2019-07-12 11:05:04.000 : INFO : DHCP : ==== Sending response to 255.255.255.255:68 ====
2019-07-12 11:05:04.000 : INFO : DHCP : s->c Opcode (op) : BootReply
s->c HardwareType (htype) : Ethernet
s->c Hops : 0
s->c XID : 3801050661
s->c Secs : 0
s->c BroadCast (flags) : True
s->c ClientIPAddress (ciaddr) : 0.0.0.0
s->c YourIPAddress (yiaddr) : 10.0.0.50
s->c NextServerIPAddress (siaddr) : 0.0.0.0
s->c RelayAgentIPAddress (giaddr) : 0.0.0.0
s->c ClientHardwareAddress (chaddr) : 08-00-27-65-12-15
s->c ServerHostName (sname) :
s->c BootFileName (file) :
s->c Option : Option(name=[MessageType],value=[ACK])
s->c Option : Option(name=[IPAddressLeaseTime],value=[1.00:00:00])
s->c Option : Option(name=[ServerIdentifier],value=[10.0.0.1])
s->c Option : Option(name=[SubnetMask],value=[255.255.255.0])
s->c Option : Option(name=[TFTPServerName],value=[10.0.0.1])
s->c Option : Option(name=[BootFileName],value=[ipxe.pxe])
Hi JP, How do you configure DHCP Options in the GUI or config.xml. e.g. bootp, Bootfile-Name etc.
I have build the DHCPServer with .net 8.
This result with success for a Windows machine.
But on Linux (Ubuntu LTS 22.04) I get absolutely no sign that the code will run.
The console output is: nothing.
I saw a difference between an old implementation from DHCPServer and the current:
The OLD was:
` protected virtual void ProcessingReceiveMessage(DHCPMessage sourceMsg, DHCPMessage targetMsg)
{
}
private void AppendConfiguredOptions(DHCPMessage sourceMsg,DHCPMessage targetMsg)
{
foreach (OptionItem optionItem in m_Options)
{
if (optionItem.Mode == OptionMode.Force || sourceMsg.IsRequestedParameter(optionItem.Option.OptionType))
{
if(targetMsg.GetOption(optionItem.Option.OptionType)==null)
{
targetMsg.Options.Add(optionItem.Option);
}
}
}
ProcessingReceiveMessage(sourceMsg, targetMsg);
}`
The NEW is:
` private void AppendConfiguredOptions(DHCPMessage sourceMsg, DHCPMessage targetMsg)
{
foreach(OptionItem optionItem in _options)
{
if(optionItem.Mode == OptionMode.Force || sourceMsg.IsRequestedParameter(optionItem.Option.OptionType))
{
if(targetMsg.GetOption(optionItem.Option.OptionType) == null)
{
targetMsg.Options.Add(optionItem.Option);
}
}
}
foreach(IDHCPMessageInterceptor interceptor in _interceptors)
{
interceptor.Apply(sourceMsg, targetMsg);
}
}`
The OLD program did use for ProcessingReceiveMessage to send a DHCP-Bootfile.
Did someone has experience with this DHCPServer Code and Linux?
Hi,
When I have the service running, it constantly disconnects my hotspot.
I was hoping I could use it to create an access portal for people connecting to my hotspot.
Is it possible to configure a Default Gateway which is published to all clients? Could you provide a sample DHCPServer.exe.config?
Hi there,
I'm evaluating DHCP libraries at the moment, so I've pulled this repo and built the GUI application. I've configured it to run a server using a static IP I've assigned my NIC, then connected a few devices through a switch to this nic. I'm not seeing any action in the log window, however.
A quickstart document would be very useful. Thanks!
Hi, is there a way to prevent the dhcp server from issuing ip's referenced in the list of reservations? it seems that if the reservations are within the pool, there can still be a conflict as the server will issue an ip that can also be taken by a reservation.
DHCPServer/DHCPServer/Library/DHCPServer.cs
Line 1016 in 34333bf
knownClient
may be null
here
Fix:
replace knownClient.LeaseDuration
with client.LeaseDuration
Hello. Is it possible to instantly see the devices connected to the DHCP server? I can see the reserves, but it does not disappear from the list when the device is disconnected.
How about every time the DHCP server gives a lease, also updates the DNS Server with the value?
Do you thing it can be done?
I know how to update an DNS server using WMI.
/// <summary>
/// DNS class for Windows DNS Server, uses WMI
/// </summary>
public class DnsProvider
{
#region Members
private ManagementScope Session = null;
/// <summary>
/// DNS Server
/// </summary>
public string Server
{
get; set;
}
/// <summary>
/// User to connect to Dns Server
/// </summary>
public string User
{
get; set;
}
/// <summary>
/// User Password to connect to Dns Server
/// </summary>
public string Password
{
get; set;
}
/// <summary>
/// DNS Domain
/// </summary>
public string UserDomain
{
get; set;
}
/// <summary>
/// Current Domain
/// </summary>
public string Domain
{
get; set;
}
#endregion
/// <summary>
/// Get values from SQL Parameter table
/// </summary>
private void GetValuesFromSQL()
{
SqlInterface sqli = new SqlInterface();
LanUser lanUser = LanUser.Get();
this.User = lanUser.UserName;
this.Password = lanUser.Password;
this.UserDomain = lanUser.DomainOrComputerName;
if (string.IsNullOrEmpty(Domain))
this.Domain = UserDomain;
if (string.IsNullOrEmpty(Server))
this.Server = Parameter.GetString("DNSserver", sqli, true);
if (string.IsNullOrEmpty(User)
|| string.IsNullOrEmpty(Password)
|| string.IsNullOrEmpty(UserDomain)
|| string.IsNullOrEmpty(Server)
)
{
throw new Exception("'LANUser','LANpassword','LANdomain','DNSServer' must be configured.");
}
}
/// <summary>
/// DNS class for Windows DNS Server, uses WMI. Constructor
/// </summary>
public DnsProvider()
{
this.GetValuesFromSQL();
this.Logon();
this.Initialize();
}
/// <summary>
/// Constructor
/// </summary>
/// <param name="serverName"></param>
/// <param name="userName"></param>
/// <param name="password"></param>
public DnsProvider(string serverName, string userName, string password)
{
this.Server = serverName;
this.User = userName;
this.Password = password;
this.Logon();
this.Initialize();
}
// Error 800703fa Illegal operation attempted on a registry key that has been marked for deletion
// Just restart App Pool and be sure in advanced settings that `Load User Profile` is true
/// <summary>
/// Logon to DNS Server
/// </summary>
private void Logon()
{
if (String.IsNullOrEmpty(this.Server))
throw new Exception("'Server' must be configured.");
this.NameSpace = "\\\\" + this.Server + "\\root\\microsoftdns";
ConnectionOptions con = new ConnectionOptions();
con.Username = this.User + "@" + this.UserDomain;
con.Password = this.Password;
con.Impersonation = ImpersonationLevel.Impersonate;
this.Session = new ManagementScope(this.NameSpace);
this.Session.Options = con;
this.Session.Connect();
}
private void Initialize()
{
}
#region Methods
/// <summary>
/// Check if A Record Exists
/// </summary>
/// <param name="domainName"></param>
/// <returns></returns>
public bool ARecordExists(string domainName = null)
{
if (String.IsNullOrEmpty(domainName))
{
domainName = this.Domain;
}
bool retval = false;
string wql = "";
wql = "SELECT *";
wql += " FROM MicrosoftDNS_ATYPE";
wql += " WHERE OwnerName = '" + domainName + "'";
ObjectQuery q = new ObjectQuery(wql);
ManagementObjectSearcher s = new ManagementObjectSearcher(this.Session, q);
ManagementObjectCollection col = s.Get();
int total = col.Count;
foreach (ManagementObject o in col)
{
retval = true;
}
s.Dispose();
return retval;
}
/// <summary>
/// Get DNS Server Domains
/// </summary>
/// <returns></returns>
public List<string> GetDomains()
{
List<string> ret = new List<string>();
ObjectQuery q = new ObjectQuery("SELECT ContainerName from MicrosoftDNS_Zone where ForwarderTimeout=0 and ZoneType=1 and ( NOT ContainerName LIKE '%.arpa') and ContainerName<>'TrustAnchors'");
ManagementObjectSearcher s = new ManagementObjectSearcher(this.Session, q);
ManagementObjectCollection col = s.Get();
foreach (ManagementObject mo in col.Cast<ManagementObject>())
{
ret.Add(Convert.ToString(mo["ContainerName"]));
}
s.Dispose();
return ret;
}
/// <summary>
/// Add Domain
/// </summary>
/// <param name="domainName"></param>
/// <param name="ipDestination"></param>
public void AddDomain(string domainName, string ipDestination)
{
//check if domain already exists
if (this.ARecordExists(domainName))
{
throw new Exception("The domain you are trying to add already exists on this server!");
}
//generate zone
using (ManagementClass man = this.Manage("MicrosoftDNS_Zone"))
{
//ManagementBaseObject ret = null;
using (ManagementBaseObject obj = man.GetMethodParameters("CreateZone"))
{
obj["ZoneName"] = domainName;
obj["ZoneType"] = 0;
//invoke method, dispose unneccesary vars
man.InvokeMethod("CreateZone", obj, null);
//this.Dispose(ref obj);
//this.Dispose(ref ret);
//add rr containing the ip destination
this.AddARecord(null, ipDestination, domainName);
}
//this.Dispose(ref man);
}
}
/// <summary>
/// Remove Domain
/// </summary>
/// <param name="domainName"></param>
public void RemoveDomain(string domainName)
{
string wql = "";
wql = "SELECT *";
wql += " FROM MicrosoftDNS_Zone";
wql += " WHERE Name = '" + domainName + "'";
ObjectQuery q = new ObjectQuery(wql);
ManagementObjectSearcher s = new ManagementObjectSearcher(this.Session, q);
ManagementObjectCollection col = s.Get();
int total = col.Count;
foreach (ManagementObject o in col)
{
o.Delete();
}
s.Dispose();
}
/// <summary>
/// Add an 'A' type Record
/// </summary>
/// <param name="aRecord"></param>
/// <param name="ipDestination"></param>
/// <param name="domainName"></param>
public void AddARecord(string aRecord, string ipDestination, string domainName = null)
{
if (String.IsNullOrEmpty(domainName))
{
domainName = this.Domain;
}
if (this.ARecordExists(aRecord + "." + domainName))
{
throw new Exception("The record '" + aRecord + "." + domainName + "' already exists!");
}
ManagementPath manpt = new ManagementPath("MicrosoftDNS_ATYPE");
using (ManagementClass man = new ManagementClass(this.Session, manpt, null))
{
using (ManagementBaseObject vars = man.GetMethodParameters("CreateInstanceFromPropertyData"))
{
vars["DnsServerName"] = this.Server;
vars["ContainerName"] = domainName;
vars["TTL"] = 300;
if (aRecord == null)
{
vars["OwnerName"] = domainName;
}
else
{
vars["OwnerName"] = aRecord + "." + domainName;
}
vars["IPAddress"] = ipDestination;
man.InvokeMethod("CreateInstanceFromPropertyData", vars, null);
}
}
}
/// <summary>
/// Remove an 'A' type Record
/// </summary>
/// <param name="aRecord"></param>
/// <param name="domainName"></param>
public void RemoveARecord(string aRecord, string domainName = null)
{
if (String.IsNullOrEmpty(domainName))
{
domainName = this.Domain;
}
string wql = "";
wql = "SELECT *";
wql += " FROM MicrosoftDNS_ATYPE";
wql += " WHERE OwnerName = '" + aRecord + "." + domainName + "'";
ObjectQuery q = new ObjectQuery(wql);
ManagementObjectSearcher s = new ManagementObjectSearcher(this.Session, q);
ManagementObjectCollection col = s.Get();
int total = col.Count;
foreach (ManagementObject o in col)
{
o.Delete();
}
s.Dispose();
}
#endregion
#region Properties
/// <summary>
/// WMI Management Namespace
/// </summary>
private string NameSpace { get; set; } = null;
private ManagementClass Manage(string path)
{
//ManagementClass retval=new ManagementClass(path);
ManagementClass retval = new ManagementClass(this.Session, new ManagementPath(path), null);
return retval;
}
#endregion
}
Thanks
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.