當前位置: 首頁>>代碼示例>>Python>>正文


Python ATMT.state方法代碼示例

本文整理匯總了Python中scapy.automaton.ATMT.state方法的典型用法代碼示例。如果您正苦於以下問題:Python ATMT.state方法的具體用法?Python ATMT.state怎麽用?Python ATMT.state使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在scapy.automaton.ATMT的用法示例。


在下文中一共展示了ATMT.state方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: reset

# 需要導入模塊: from scapy.automaton import ATMT [as 別名]
# 或者: from scapy.automaton.ATMT import state [as 別名]
def reset(self, iface=None, client_mac=None, xid=None, scriptfile=None):
        """Reset object attributes when state is INIT."""
        logger.debug('Reseting attributes.')
        if iface is None:
            iface = conf.iface
        if client_mac is None:
            # scapy for python 3 returns byte, not tuple
            tempmac = get_if_raw_hwaddr(iface)
            if isinstance(tempmac, tuple) and len(tempmac) == 2:
                mac = tempmac[1]
            else:
                mac = tempmac
            client_mac = str2mac(mac)
        self.client = DHCPCAP(iface=iface, client_mac=client_mac, xid=xid)
        if scriptfile is not None:
            self.script = ClientScript(scriptfile)
        else:
            self.script = None
        self.time_sent_request = None
        self.discover_attempts = 0
        self.request_attempts = 0
        self.current_state = STATE_PREINIT
        self.offers = list() 
開發者ID:juga0,項目名稱:dhcpcanon,代碼行數:25,代碼來源:dhcpcapfsm.py

示例2: BOUND

# 需要導入模塊: from scapy.automaton import ATMT [as 別名]
# 或者: from scapy.automaton.ATMT import state [as 別名]
def BOUND(self):
        """BOUND state."""
        logger.debug('In state: BOUND')
        logger.info('(%s) state changed %s -> bound', self.client.iface,
                    STATES2NAMES[self.current_state])
        self.current_state = STATE_BOUND
        self.client.lease.info_lease()
        if self.script is not None:
            self.script.script_init(self.client.lease, self.current_state)
            self.script.script_go()
        else:
            try:
                set_net(self.client.lease)
            except Exception as e:
                logger.error('Can not set IP', exc_info=True)
                # raise self.END()
        # TODO: go daemon? 
開發者ID:juga0,項目名稱:dhcpcanon,代碼行數:19,代碼來源:dhcpcapfsm.py

示例3: timeout_requesting

# 需要導入模塊: from scapy.automaton import ATMT [as 別名]
# 或者: from scapy.automaton.ATMT import state [as 別名]
def timeout_requesting(self):
        """Timeout requesting in REQUESTING state.

        Not specifiyed in [:rfc:`7844`]

        [:rfc:`2131#section-3.1`]::

            might retransmit the
            DHCPREQUEST message four times, for a total delay of 60 seconds

        """
        logger.debug("C3.2: T. In %s, timeout receiving response to request, ",
                     self.current_state)
        if self.discover_requests >= MAX_ATTEMPTS_REQUEST:
            logger.debug('C2.3: T. Maximum number %s of REQUESTs '
                         'reached, already sent %s, raise ERROR.',
                         MAX_ATTEMPTS_REQUEST, self.disover_requests)
            raise self.ERROR()
        logger.debug("C2.3: F. Maximum number of REQUESTs retries not reached,"
                     "raise REQUESTING.")
        raise self.REQUESTING() 
開發者ID:juga0,項目名稱:dhcpcanon,代碼行數:23,代碼來源:dhcpcapfsm.py

示例4: timeout_request_renewing

# 需要導入模塊: from scapy.automaton import ATMT [as 別名]
# 或者: from scapy.automaton.ATMT import state [as 別名]
def timeout_request_renewing(self):
        """Timeout of renewing on RENEWING state.

        Same comments as in
        :func:`dhcpcapfsm.DHCPCAPFSM.timeout_requesting`.

        """
        logger.debug("C5.2:T In %s, timeout receiving response to request.",
                     self.current_state)
        if self.request_attempts >= MAX_ATTEMPTS_REQUEST:
            logger.debug('C2.3: T Maximum number %s of REQUESTs '
                         'reached, already sent %s, wait to rebinding time.',
                         MAX_ATTEMPTS_REQUEST, self.disover_requests)
            # raise self.ERROR()
        logger.debug("C2.3: F. Maximum number of REQUESTs retries not reached,"
                     "raise RENEWING.")
        raise self.RENEWING() 
開發者ID:juga0,項目名稱:dhcpcanon,代碼行數:19,代碼來源:dhcpcapfsm.py

示例5: lease_expires

# 需要導入模塊: from scapy.automaton import ATMT [as 別名]
# 或者: from scapy.automaton.ATMT import state [as 別名]
def lease_expires(self):
        """Timeout lease time, transition to INIT.

        Not sending DHCPRELEASE to minimize deanonymization

        [:rfc:`2131#section-4.4.6`]::

            Note that the correct operation
            of DHCP does not depend on the transmission of DHCPRELEASE.

        """
        logger.debug("C6.3. Timeout lease time, in REBINDING state, "
                     "raise INIT.")
        raise self.STATE_INIT()

    # RECEIVE CONDITIONS
    #################### 
開發者ID:juga0,項目名稱:dhcpcanon,代碼行數:19,代碼來源:dhcpcapfsm.py

示例6: receive_offer

# 需要導入模塊: from scapy.automaton import ATMT [as 別名]
# 或者: from scapy.automaton.ATMT import state [as 別名]
def receive_offer(self, pkt):
        """Receive offer on SELECTING state."""
        logger.debug("C2. Received OFFER?, in SELECTING state.")
        if isoffer(pkt):
            logger.debug("C2: T, OFFER received")
            self.offers.append(pkt)
            if len(self.offers) >= MAX_OFFERS_COLLECTED:
                logger.debug("C2.5: T, raise REQUESTING.")
                self.select_offer()
                raise self.REQUESTING()
            logger.debug("C2.5: F, raise SELECTING.")
            raise self.SELECTING()

    # same as:, but would can not be overloaded
    # @ATMT.receive_condition(RENEWING)
    # @ATMT.receive_condition(REBINDING) 
開發者ID:juga0,項目名稱:dhcpcanon,代碼行數:18,代碼來源:dhcpcapfsm.py

示例7: get_timeout

# 需要導入模塊: from scapy.automaton import ATMT [as 別名]
# 或者: from scapy.automaton.ATMT import state [as 別名]
def get_timeout(self, state, function):
        """Workaround to get timeout in the ATMT.timeout class method."""
        state = STATES2NAMES[state]
        for timeout_fn_t in self.timeout[state]:
            # access the function name
            if timeout_fn_t[1] is not None and \
               timeout_fn_t[1].atmt_condname == function.atmt_condname:
                logger.debug('Timeout for state %s, function %s, is %s',
                             state, function.atmt_condname, timeout_fn_t[0])
                return timeout_fn_t[0]
        return None 
開發者ID:juga0,項目名稱:dhcpcanon,代碼行數:13,代碼來源:dhcpcapfsm.py

示例8: set_timeout

# 需要導入模塊: from scapy.automaton import ATMT [as 別名]
# 或者: from scapy.automaton.ATMT import state [as 別名]
def set_timeout(self, state, function, newtimeout):
        """
        Workaround to change timeout values in the ATMT.timeout class method.

        self.timeout format is::

            {'STATE': [
                (TIMEOUT0, <function foo>),
                (TIMEOUT1, <function bar>)),
                (None, None)
                ],
            }


        """
        state = STATES2NAMES[state]
        for timeout_fn_t in self.timeout[state]:
            # access the function name
            if timeout_fn_t[1] is not None and \
               timeout_fn_t[1].atmt_condname == function.atmt_condname:
                # convert list to tuple to make it mutable
                timeout_l = list(timeout_fn_t)
                # modify the timeout
                timeout_l[0] = newtimeout
                # set the new timeoute to self.timeout
                i = self.timeout[state].index(timeout_fn_t)
                self.timeout[state][i] = tuple(timeout_l)
                logger.debug('Set state %s, function %s, to timeout %s',
                             state, function.atmt_condname, newtimeout) 
開發者ID:juga0,項目名稱:dhcpcanon,代碼行數:31,代碼來源:dhcpcapfsm.py

示例9: process_received_ack

# 需要導入模塊: from scapy.automaton import ATMT [as 別名]
# 或者: from scapy.automaton.ATMT import state [as 別名]
def process_received_ack(self, pkt):
        """Process a received ACK packet.

        Not specifiyed in [:rfc:`7844`].
        Probe the offered IP in [:rfc:`2131#section-2.2.`]::

            the allocating
            server SHOULD probe the reused address before allocating the
            address, e.g., with an ICMP echo request, and the client SHOULD
            probe the newly received address, e.g., with ARP.

            The client SHOULD broadcast an ARP
            reply to announce the client's new IP address and clear any
            outdated ARP cache entries in hosts on the client's subnet.

        It is also not specifiyed in [:rfc:`7844`] nor [:rfc:`2131`] how to
        check that the offered IP is valid.

        .. todo::
           - Check that nor ``dhclient`` nor ``systemd-networkd`` send an ARP.
           - Check how other implementations check that the ACK paremeters
             are valid, ie, if the ACK fields match the fields in the OFFER.
           - Check to which state the client should go back to when the
             offered parameters are not valid.

        """
        if isack(pkt):
            try:
                self.event = self.client.handle_ack(pkt,
                                                    self.time_sent_request)
            except AddrFormatError as err:
                logger.error(err)
                # NOTE: see previous TODO, maybe should go back to other state.
                raise self.SELECTING()
            # NOTE: see previous TODO, not checking address with ARP.
            logger.info('DHCPACK of %s from %s' %
                        (self.client.client_ip, self.client.server_ip))
            return True
        return False 
開發者ID:juga0,項目名稱:dhcpcanon,代碼行數:41,代碼來源:dhcpcapfsm.py

示例10: SELECTING

# 需要導入模塊: from scapy.automaton import ATMT [as 別名]
# 或者: from scapy.automaton.ATMT import state [as 別名]
def SELECTING(self):
        """SELECTING state."""
        logger.debug('In state: SELECTING')
        self.current_state = STATE_SELECTING 
開發者ID:juga0,項目名稱:dhcpcanon,代碼行數:6,代碼來源:dhcpcapfsm.py

示例11: REQUESTING

# 需要導入模塊: from scapy.automaton import ATMT [as 別名]
# 或者: from scapy.automaton.ATMT import state [as 別名]
def REQUESTING(self):
        """REQUESTING state."""
        logger.debug('In state: REQUESTING')
        self.current_state = STATE_REQUESTING 
開發者ID:juga0,項目名稱:dhcpcanon,代碼行數:6,代碼來源:dhcpcapfsm.py

示例12: RENEWING

# 需要導入模塊: from scapy.automaton import ATMT [as 別名]
# 或者: from scapy.automaton.ATMT import state [as 別名]
def RENEWING(self):
        """RENEWING state."""
        logger.debug('In state: RENEWING')
        self.current_state = STATE_RENEWING
        if self.script is not None:
            self.script.script_init(self.client.lease, self.current_state)
            self.script.script_go()
        else:
            set_net(self.client.lease) 
開發者ID:juga0,項目名稱:dhcpcanon,代碼行數:11,代碼來源:dhcpcapfsm.py

示例13: REBINDING

# 需要導入模塊: from scapy.automaton import ATMT [as 別名]
# 或者: from scapy.automaton.ATMT import state [as 別名]
def REBINDING(self):
        """REBINDING state."""
        logger.debug('In state: REBINDING')
        self.current_state = STATE_REBINDING
        if self.script is not None:
            self.script.script_init(self.client.lease, self.current_state)
            self.script.script_go()
        else:
            set_net(self.client.lease) 
開發者ID:juga0,項目名稱:dhcpcanon,代碼行數:11,代碼來源:dhcpcapfsm.py

示例14: ERROR

# 需要導入模塊: from scapy.automaton import ATMT [as 別名]
# 或者: from scapy.automaton.ATMT import state [as 別名]
def ERROR(self):
        """ERROR state."""
        logger.debug('In state: ERROR')
        self.current_state = STATE_ERROR
        if self.script is not None:
            self.script.script_init(self.client.lease, self.current_state)
            self.script.script_go()
        set_net(self.client.lease)
        raise self.INIT()

    # TIMEOUTS
    ###########

    # TIMEOUTS: retransmissions
    # ---------------------------- 
開發者ID:juga0,項目名稱:dhcpcanon,代碼行數:17,代碼來源:dhcpcapfsm.py

示例15: timeout_delay_before_selecting

# 需要導入模塊: from scapy.automaton import ATMT [as 別名]
# 或者: from scapy.automaton.ATMT import state [as 別名]
def timeout_delay_before_selecting(self):
        """Timeout delay selecting in INIT state."""
        logger.debug('C1:T. In %s, timeout delay selecting, raise SELECTING',
                     self.current_state)
        raise self.SELECTING() 
開發者ID:juga0,項目名稱:dhcpcanon,代碼行數:7,代碼來源:dhcpcapfsm.py


注:本文中的scapy.automaton.ATMT.state方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。