Added server detection
Implemented server detection at the request of NTEWIZ. If not detected, it will ask after collecting pull data.
This commit is contained in:
parent
9eae9b4a15
commit
cc88955baf
15 changed files with 242 additions and 7 deletions
|
|
@ -144,6 +144,9 @@ def run_live_capture(
|
|||
resolved_user_uid = user_uid or session.user_uid
|
||||
if session.kinds_seen() and not resolved_user_uid:
|
||||
resolved_user_uid = console.prompt_user_uid()
|
||||
resolved_server_id = session.server_id
|
||||
if session.kinds_seen() and not resolved_server_id:
|
||||
resolved_server_id = console.prompt_server_id()
|
||||
capture_source = CAPTURE_SOURCE_LABELS.get(capture.name, capture.name)
|
||||
for kind in session.kinds_seen():
|
||||
pairs = session.pairs_for_kind(kind)
|
||||
|
|
@ -162,6 +165,7 @@ def run_live_capture(
|
|||
source="live_capture",
|
||||
capture_source=capture_source,
|
||||
user_uid=resolved_user_uid,
|
||||
server_id=resolved_server_id,
|
||||
pages_seen=pages_seen,
|
||||
)
|
||||
payload = json.dumps(export, ensure_ascii=False, indent=2)
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@ from nte_history_exporter.decoder.mystery_box import (
|
|||
from nte_history_exporter.decoder.structured_protocol import FORK_MARKER, MONOPOLY_MARKER
|
||||
from nte_history_exporter.constants import MYSTERY_BOX_MARKER
|
||||
from nte_history_exporter.decoder.user_uid import extract_user_uid_candidates
|
||||
from nte_history_exporter.decoder.server_region import extract_server_id
|
||||
from nte_history_exporter.live_capture.diagnostics import CaptureDiagnostics
|
||||
|
||||
|
||||
|
|
@ -72,6 +73,7 @@ class LiveHistorySession:
|
|||
self.unanswered_pages: dict[str, dict[int, str]] = {}
|
||||
self.user_uid: str | None = None
|
||||
self.user_uid_candidates: Counter[str] = Counter()
|
||||
self.server_id: str | None = None
|
||||
self.diagnostics = CaptureDiagnostics()
|
||||
|
||||
def _mark_unanswered(self, request: PendingRequest) -> None:
|
||||
|
|
@ -122,6 +124,11 @@ class LiveHistorySession:
|
|||
if candidates:
|
||||
self.user_uid_candidates.update(candidates)
|
||||
self.user_uid = self.user_uid_candidates.most_common(1)[0][0]
|
||||
if packet.protocol == "tcp" and packet.dst_ip == self.local_ip and not self.server_id:
|
||||
self.server_id = extract_server_id(packet.payload)
|
||||
if self.server_id:
|
||||
self.diagnostics.counters["server_ids_detected"] += 1
|
||||
self.diagnostics.add_event("SERVER_ID_DETECTED", self.packet_count)
|
||||
if packet.protocol != "udp":
|
||||
return False
|
||||
|
||||
|
|
|
|||
|
|
@ -5,6 +5,41 @@ import select
|
|||
import sys
|
||||
|
||||
|
||||
def _read_windows_key() -> None:
|
||||
import msvcrt
|
||||
|
||||
key = msvcrt.getch()
|
||||
# Function and arrow keys are emitted as a two-byte sequence. Consume the
|
||||
# second byte so it cannot immediately satisfy the next key prompt.
|
||||
if key in {b"\x00", b"\xe0"}:
|
||||
msvcrt.getch()
|
||||
|
||||
|
||||
def wait_for_keypress() -> None:
|
||||
"""Wait for one key on an interactive terminal, or Enter on redirected input."""
|
||||
if os.name == "nt" and sys.stdin.isatty():
|
||||
_read_windows_key()
|
||||
return
|
||||
|
||||
if not sys.stdin.isatty():
|
||||
try:
|
||||
input()
|
||||
except EOFError:
|
||||
pass
|
||||
return
|
||||
|
||||
import termios
|
||||
import tty
|
||||
|
||||
fd = sys.stdin.fileno()
|
||||
original_terminal = termios.tcgetattr(fd)
|
||||
try:
|
||||
tty.setcbreak(fd)
|
||||
os.read(fd, 1)
|
||||
finally:
|
||||
termios.tcsetattr(fd, termios.TCSADRAIN, original_terminal)
|
||||
|
||||
|
||||
class StopKeyMonitor:
|
||||
def __init__(self) -> None:
|
||||
self._windows = os.name == "nt"
|
||||
|
|
@ -29,7 +64,7 @@ class StopKeyMonitor:
|
|||
|
||||
if not msvcrt.kbhit():
|
||||
return False
|
||||
msvcrt.getch()
|
||||
_read_windows_key()
|
||||
return True
|
||||
|
||||
if self._fd is None:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue