Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:

Скрипты / capture_step1_robust

.py
Скачиваний:
0
Добавлен:
15.11.2026
Размер:
2 Кб
Скачать
☆
import subprocess
import time
from PIL import Image
import numpy as np

VBOX = r"C:\Program Files\Oracle\VirtualBox\VBoxManage.exe"
VM = "ЗиВКС"

def ensure_en():
    subprocess.run([VBOX, "controlvm", VM, "screenshotpng", r"C:\Users\omni\Desktop\tusur\ЗИвКС\LR6\screenshots_real\temp_screen.png"], check=True)
    img = Image.open(r"C:\Users\omni\Desktop\tusur\ЗИвКС\LR6\screenshots_real\temp_screen.png")
    box = np.array(img.crop((1143, 754, 1184, 788)).convert('L'))
    en_ref = np.array(Image.open(r"C:\Users\omni\Desktop\tusur\ЗИвКС\LR6\screenshots_real\en_ref_exact.png").convert('L'))
    diff = np.sum(np.abs(box.astype(int) - en_ref.astype(int)))
    if diff > 4000:
        subprocess.run([VBOX, "controlvm", VM, "keyboardputscancode", "38", "2a", "aa", "b8"])
        time.sleep(0.3)

def type_cmd(cmd, wait=1.5):
    ensure_en()
    subprocess.run([VBOX, "controlvm", VM, "keyboardputstring", cmd], check=True)
    time.sleep(0.05)
    subprocess.run([VBOX, "controlvm", VM, "keyboardputscancode", "1c", "9c"], check=True)
    time.sleep(wait)

def send_sc(sc_list, wait=0.3):
    subprocess.run([VBOX, "controlvm", VM, "keyboardputscancode", *sc_list], check=True)
    time.sleep(wait)

# Clear current line
send_sc(["1d", "2e", "ae", "9d"]) # Ctrl+C
time.sleep(0.5)

type_cmd("clear")
type_cmd("nmcli connection modify 'Проводное соединение 1' ipv4.method manual ipv4.addresses 10.0.2.4/24 ipv4.gateway 10.0.2.1 ipv4.dns '77.88.8.8' ipv4.dns-search 'bea7341.local'")
type_cmd("nmcli connection up 'Проводное соединение 1'")

# Launch nm-connection-editor in background
type_cmd("nm-connection-editor &", wait=2.5)

# In nm-connection-editor list, press Enter to open edit dialog for "Проводное соединение 1"
send_sc(["1c", "9c"], wait=2.0)

# Switch to IPv4 tab: 4 times Ctrl+PageDown
for _ in range(4):
    send_sc(["1d", "e0", "51", "e0", "d1", "9d"], wait=0.4)

time.sleep(1.0)
out_file = r"C:\Users\omni\Desktop\tusur\ЗИвКС\LR6\screenshots_real\1_network_config_dc.png"
subprocess.run([VBOX, "controlvm", VM, "screenshotpng", out_file], check=True)
print("SUCCESS: Captured 1_network_config_dc.png")
Соседние файлы в папке Скрипты