Example #1
0
    def GetNextDhcpPacket(self) :
        if self.filedesc and self.binary :
            packet = dhcp_packet.DhcpPacket()
            data = self.filedesc.read(4096)
            packet.DecodePacket(data)
            return packet

        elif self.filedesc and not self.binary :
            packet = dhcp_packet.DhcpPacket()
            for line in self.filedesc : packet.AddLine(line)
            return packet
Example #2
0
    def HandleDhcpPacket(self, data, sender):
        packet = dhcp_packet.DhcpPacket()
        packet.DecodePacket(data)

        packet.set_sender( sender )

        self.HandleDhcpAll(packet)
        
        if packet.IsDhcpDiscoverPacket():
            self.HandleDhcpDiscover(packet)
        elif packet.IsDhcpRequestPacket():
            self.HandleDhcpRequest(packet)
        elif packet.IsDhcpDeclinePacket():
            self.HandleDhcpDecline(packet)
        elif packet.IsDhcpReleasePacket():
            self.HandleDhcpRelease(packet)
        elif packet.IsDhcpInformPacket():
            self.HandleDhcpInform(packet)
        elif packet.IsDhcpOfferPacket():
            self.HandleDhcpOffer(packet)
        elif packet.IsDhcpAckPacket():
            self.HandleDhcpAck(packet)
        elif packet.IsDhcpNackPacket():
            self.HandleDhcpNack(packet)
        else: self.HandleDhcpUnknown(packet)

        return packet
Example #3
0
def r_conversion():
    rawdata = rawdata = sys.stdin.read()
    while (len(rawdata) > 0):
        readdata = dhcp_packet.DhcpPacket()
        readdata.DecodePacket(rawdata)
        readdata.PrintHeaders()
        readdata.PrintOptions()
        rawdata = rawdata = sys.stdin.read()
Example #4
0
    def GetNextDhcpPacket(self, timeout=60):
        data = ""

        while data == "":

            data_input, data_output, data_except = select.select(
                [self.dhcp_socket], [], [], timeout)

            if (data_input != []):
                (data, source_address) = self.dhcp_socket.recvfrom(2048)
            else:
                return None

            if data != "":
                packet = dhcp_packet.DhcpPacket()
                packet.source_address = source_address
                packet.DecodePacket(data)

                self.HandleDhcpAll(packet)

                if packet.IsDhcpDiscoverPacket():
                    self.HandleDhcpDiscover(packet)
                elif packet.IsDhcpRequestPacket():
                    self.HandleDhcpRequest(packet)
                elif packet.IsDhcpDeclinePacket():
                    self.HandleDhcpDecline(packet)
                elif packet.IsDhcpReleasePacket():
                    self.HandleDhcpRelease(packet)
                elif packet.IsDhcpInformPacket():
                    self.HandleDhcpInform(packet)
                elif packet.IsDhcpOfferPacket():
                    self.HandleDhcpOffer(packet)
                elif packet.IsDhcpAckPacket():
                    self.HandleDhcpAck(packet)
                elif packet.IsDhcpNackPacket():
                    self.HandleDhcpNack(packet)
                else:
                    self.HandleDhcpUnknown(packet)

                return packet