Class/DhcpDiscoverPacket.psm1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
using module '.\Enums.psm1' using module '.\DhcpOptionObject.psm1' using module '.\DhcpPacket.psm1' # DHCP Discover Packet class class DhcpDiscoverPacket : DhcpPacket { [byte[]]$ParameterRequestList = @( [DhcpOption]::SubnetMask, [DhcpOption]::Router, [DhcpOption]::DomainNameServer, [DhcpOption]::DomainName, [DhcpOption]::RouterDiscovery, [DhcpOption]::StaticRoute, [DhcpOption]::NTPServers, [DhcpOption]::DomainSearch, [DhcpOption]::WebProxyAutoDiscovery ) [ValidateNotNull()][ipaddress]$RequestedIPAddress = [ipaddress]::Any DhcpDiscoverPacket([PhysicalAddress]$MacAddress) : base() { [Random]::new().NextBytes($this.XID) $this.CHAddr = $MacAddress $this.AddDhcpOptions(@( [DhcpOptionObject]::new([DhcpOption]::DHCPMessageType, [DhcpMessageType]::DHCPDISCOVER), [DhcpOptionObject]::new([DhcpOption]::RequestedIPAddress, $this.RequestedIPAddress.GetAddressBytes()), [DhcpOptionObject]::new([DhcpOption]::ParameterRequestList, $this.ParameterRequestList), [DhcpOptionObject]::new([DhcpOption]::End, $null) )) } [byte[]]GetPacketBytes() { if (-not ($this._DhcpOptionsList.Keys -eq 61)) { $this.AddDhcpOptions( [DhcpOptionObject]::new([DhcpOption]::ClientId, (([byte[]]0x01) + $this.CHAddr.GetAddressBytes())) ) } $this.AddDhcpOptions(@( [DhcpOptionObject]::new([DhcpOption]::RequestedIPAddress, $this.RequestedIPAddress.GetAddressBytes()), [DhcpOptionObject]::new([DhcpOption]::ParameterRequestList, $this.ParameterRequestList) )) return ([DhcpPacket]$this).GetPacketBytes() } } |