douyinWEB/scripts/_probe_phys_guest_identity.py
2026-09-13 22:10:49 -05:00

53 lines
1.7 KiB
Python

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""Identify which guest we hit via FRP:4014 vs PVE VM 103."""
from __future__ import annotations
import sys
import paramiko
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
REMOTE = """#!/bin/bash
echo '=== identity ==='
hostname -f 2>/dev/null || hostname
cat /etc/hostname 2>/dev/null
echo '=== MAC / IP ==='
ip -br link
ip -br addr
echo '=== mem / balloon ==='
free -h
grep -E 'MemTotal|MemAvailable|SwapTotal|SwapFree' /proc/meminfo
# virtio balloon often shows under /sys
ls /sys/bus/virtio/devices 2>/dev/null
find /sys -name '*balloon*' 2>/dev/null | head -20
cat /sys/devices/system/memory/block_size_bytes 2>/dev/null
echo memory_blocks=$(ls -d /sys/devices/system/memory/memory* 2>/dev/null | wc -l)
echo '=== dmidecode mem (if any) ==='
dmidecode -t 17 2>/dev/null | grep -E 'Size:|Locator:' | head -20 || true
echo '=== qemu guest agent? ==='
systemctl is-active qemu-guest-agent 2>/dev/null || true
which qemu-ga 2>/dev/null || true
echo '=== neko present? ==='
docker ps --format '{{.Names}}' 2>/dev/null | grep -E 'neko|douyin' | head -20
"""
def main() -> int:
c = paramiko.SSHClient()
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
c.connect("107.173.30.245", 4014, "eric", "4669805", timeout=40, allow_agent=False, look_for_keys=False)
sftp = c.open_sftp()
with sftp.file("/tmp/_id_guest.sh", "w") as f:
f.write(REMOTE)
sftp.close()
_, o, e = c.exec_command("echo '4669805' | sudo -S -p '' bash /tmp/_id_guest.sh", timeout=60)
print((o.read() + e.read()).decode("utf-8", "replace"))
c.close()
return 0
if __name__ == "__main__":
raise SystemExit(main())