Пример #1
0
        private static void V4Request()
        {
            var V4Message = new DhcpV4Message(IPAddress.Any,
                                              new IPEndPoint(IPAddress.Parse("192.168.61.48"), DhcpConstants.V4_SERVER_PORT));

            V4Message.SetOp((short)DhcpConstants.V4_OP_REQUEST); //V4_OP_REQUEST
            V4Message.SetGiAddr(IPAddress.Any);
            V4Message.SetChAddr(PhysicalAddress.Parse("9C-EB-E8-28-92-D4").GetAddressBytes());

            DhcpV4MsgTypeOption msgTypeOption = new DhcpV4MsgTypeOption();

            msgTypeOption.SetUnsignedByte((short)DhcpConstants.V4MESSAGE_TYPE_REQUEST);
            V4Message.PutDhcpOption(msgTypeOption);

            V4Message.PutDhcpOption(new DhcpV4RequestedIpAddressOption(
                                        new v4RequestedIpAddressOption()
            {
                code      = DhcpConstants.V4OPTION_REQUESTED_IP,
                ipAddress = "192.168.61.140"
            }));
            V4Message.SetDhcpV4ServerIdOption(
                new DhcpV4ServerIdOption(
                    new v4ServerIdOption()
            {
                code      = DhcpConstants.V4OPTION_SERVERID,
                ipAddress = "192.168.61.48"
            }));
            var message = DhcpV4MessageHandler.HandleMessage(
                IPAddress.Parse("192.168.61.48"), V4Message);

            Console.WriteLine(message.ToString());
        }
Пример #2
0
        public void SetMessageType(short msgType)
        {
            DhcpV4MsgTypeOption msgTypeOption = new DhcpV4MsgTypeOption();

            msgTypeOption.SetUnsignedByte(msgType);
            PutDhcpOption(msgTypeOption);
        }
Пример #3
0
            /**
             * Builds the discover message.
             *
             * @return the  dhcp message
             */
            private DhcpV4Message BuildDiscoverMessage(byte[] chAddr)
            {
                DhcpV4Message msg = new DhcpV4Message(IPAddress.Parse("0.0.0.0"), new IPEndPoint(serverAddr, serverPort));

                msg.SetOp((short)DhcpConstants.V4_OP_REQUEST);
                msg.SetTransactionId(GetRandomLong());
                msg.SetHtype((short)1); // ethernet
                msg.SetHlen((byte)6);
                msg.SetChAddr(chAddr);
                msg.SetGiAddr(clientAddr);  // look like a relay to the DHCP server

                DhcpV4MsgTypeOption msgTypeOption = new DhcpV4MsgTypeOption();

                msgTypeOption.SetUnsignedByte((short)DhcpConstants.V4MESSAGE_TYPE_DISCOVER);

                msg.PutDhcpOption(msgTypeOption);

                return(msg);
            }
Пример #4
0
            private DhcpV4Message BuildReleaseMessage(DhcpV4Message ack)
            {
                DhcpV4Message msg = new DhcpV4Message(null, new IPEndPoint(serverAddr, serverPort));

                msg.SetOp((short)DhcpConstants.V4_OP_REQUEST);
                msg.SetTransactionId(ack.GetTransactionId());
                msg.SetHtype((short)1); // ethernet
                msg.SetHlen((byte)6);
                msg.SetChAddr(ack.GetChAddr());
                msg.SetGiAddr(clientAddr);  // look like a relay to the DHCP server
                msg.SetCiAddr(ack.GetYiAddr());

                DhcpV4MsgTypeOption msgTypeOption = new DhcpV4MsgTypeOption();

                msgTypeOption.SetUnsignedByte((short)DhcpConstants.V4MESSAGE_TYPE_RELEASE);

                msg.PutDhcpOption(msgTypeOption);

                return(msg);
            }
Пример #5
0
        private static void V4Discover()
        {
            var V4Message = new DhcpV4Message(IPAddress.Any,
                                              new IPEndPoint(IPAddress.Parse("192.168.61.48"), DhcpConstants.V4_SERVER_PORT));

            V4Message.SetOp((short)DhcpConstants.V4_OP_REQUEST); //V4_OP_REQUEST
            V4Message.SetGiAddr(IPAddress.Any);
            V4Message.SetChAddr(PhysicalAddress.Parse("9C-EB-E8-28-92-D4").GetAddressBytes());
            V4Message.SetHlen(6);
            V4Message.SetHtype((byte)6);
            V4Message.SetTransactionId(-1729018559);

            DhcpV4MsgTypeOption msgTypeOption = new DhcpV4MsgTypeOption();

            msgTypeOption.SetUnsignedByte((short)DhcpConstants.V4MESSAGE_TYPE_DISCOVER);
            V4Message.PutDhcpOption(msgTypeOption);

            var message = DhcpV4MessageHandler.HandleMessage(
                IPAddress.Parse("192.168.61.48"), V4Message);

            Console.WriteLine(message.ToString());
        }
Пример #6
0
            private DhcpV4Message BuildRequestMessage(DhcpV4Message offer)
            {
                DhcpV4Message msg = new DhcpV4Message(IPAddress.Parse("0.0.0.0"), new IPEndPoint(serverAddr, serverPort));

                msg.SetOp((short)DhcpConstants.V4_OP_REQUEST);
                msg.SetTransactionId(offer.GetTransactionId());
                msg.SetHtype((short)1); // ethernet
                msg.SetHlen((byte)6);
                msg.SetChAddr(offer.GetChAddr());
                msg.SetGiAddr(clientAddr);  // look like a relay to the DHCP server

                DhcpV4MsgTypeOption msgTypeOption = new DhcpV4MsgTypeOption();

                msgTypeOption.SetUnsignedByte((short)DhcpConstants.V4MESSAGE_TYPE_REQUEST);

                msg.PutDhcpOption(msgTypeOption);

                DhcpV4RequestedIpAddressOption reqIpOption = new DhcpV4RequestedIpAddressOption();

                reqIpOption.SetIpAddress(offer.GetYiAddr().ToString());
                msg.PutDhcpOption(reqIpOption);

                return(msg);
            }