diff --git a/dhcpcanon/dhcpcanon.py b/dhcpcanon/dhcpcanon.py index 75988f9..0f13452 100755 --- a/dhcpcanon/dhcpcanon.py +++ b/dhcpcanon/dhcpcanon.py @@ -36,6 +36,9 @@ def main(): parser.add_argument('--version', action='version', help='version', version='%(prog)s ' + __version__) + parser.add_argument('-s', '--delay_selecting', + help='Selecting starts after a ramdon delay.', + action='store_true') # options to looks like dhclient parser.add_argument( '-sf', metavar='script-file', nargs='?', @@ -104,7 +107,8 @@ def main(): dhcpcap = DHCPCAPFSM(iface=conf.iface, server_port=SERVER_PORT, client_port=CLIENT_PORT, - scriptfile=args.sf) + scriptfile=args.sf, + delay_selecting=args.delay_selecting) dhcpcap.run() diff --git a/dhcpcanon/dhcpcapfsm.py b/dhcpcanon/dhcpcapfsm.py index 52bdd28..98f5315 100644 --- a/dhcpcanon/dhcpcapfsm.py +++ b/dhcpcanon/dhcpcapfsm.py @@ -71,7 +71,8 @@ def reset(self, iface=None, client_mac=None, xid=None, scriptfile=None): def __init__(self, iface=None, server_port=None, client_port=None, client_mac=None, xid=None, - scriptfile=None, delay_before_selecting=None, + scriptfile=None, delay_selecting=False, + delay_before_selecting=None, timeout_select=None, debug_level=5, *args, **kargs): """Overwrites Automaton __init__ method. @@ -84,6 +85,7 @@ def __init__(self, iface=None, server_port=None, logger.debug('Inizializating FSM.') super(DHCPCAPFSM, self).__init__(*args, **kargs) self.debug_level = debug_level + self.delay_selecting = delay_selecting self.delay_before_selecting = delay_before_selecting self.timeout_select = timeout_select self.reset(iface, client_mac, xid, scriptfile) @@ -323,10 +325,13 @@ def INIT(self): self.reset() self.current_state = STATE_INIT # NOTE: see previous TODO, maybe this is not needed. - if self.delay_before_selecting is None: - delay_before_selecting = gen_delay_selecting() + if self.delay_selecting: + if self.delay_before_selecting is None: + delay_before_selecting = gen_delay_selecting() + else: + delay_before_selecting = self.delay_before_selecting else: - delay_before_selecting = self.delay_before_selecting + delay_before_selecting = 0 self.set_timeout(self.current_state, self.timeout_delay_before_selecting, delay_before_selecting)