forked from p15670423/monkey
Agent: Add sleep back into _check_tcp_ports()
This commit is contained in:
parent
21ede3e341
commit
36a2b3ff6b
|
@ -1,6 +1,7 @@
|
||||||
import logging
|
import logging
|
||||||
import select
|
import select
|
||||||
import socket
|
import socket
|
||||||
|
import time
|
||||||
from typing import Iterable, Mapping, Tuple
|
from typing import Iterable, Mapping, Tuple
|
||||||
|
|
||||||
from infection_monkey.i_puppet import PortScanData, PortStatus
|
from infection_monkey.i_puppet import PortScanData, PortStatus
|
||||||
|
@ -9,6 +10,8 @@ from infection_monkey.utils.timer import Timer
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
POLL_INTERVAL = 0.5
|
||||||
|
|
||||||
|
|
||||||
def scan_tcp_ports(
|
def scan_tcp_ports(
|
||||||
host: str, ports_to_scan: Iterable[int], timeout: float
|
host: str, ports_to_scan: Iterable[int], timeout: float
|
||||||
|
@ -83,6 +86,10 @@ def _check_tcp_ports(
|
||||||
timer.set(timeout)
|
timer.set(timeout)
|
||||||
|
|
||||||
while (not timer.is_expired()) and sockets_to_try:
|
while (not timer.is_expired()) and sockets_to_try:
|
||||||
|
# The call to select() may return sockets that are writeable but not actually
|
||||||
|
# connected. Adding this sleep prevents excessive looping.
|
||||||
|
time.sleep(min(POLL_INTERVAL, timer.time_remaining))
|
||||||
|
|
||||||
sock_objects = [s[1] for s in sockets_to_try]
|
sock_objects = [s[1] for s in sockets_to_try]
|
||||||
|
|
||||||
_, writeable_sockets, _ = select.select([], sock_objects, [], timer.time_remaining)
|
_, writeable_sockets, _ = select.select([], sock_objects, [], timer.time_remaining)
|
||||||
|
|
Loading…
Reference in New Issue