30 lines
964 B
Python
Executable File
30 lines
964 B
Python
Executable File
#!/usr/bin/env python3
|
|
import sys
|
|
import time
|
|
import socket
|
|
import json
|
|
|
|
def qmp_screendump(sock_path, out_file):
|
|
try:
|
|
s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
|
|
s.settimeout(10)
|
|
s.connect(sock_path)
|
|
s.recv(4096) # QMP greeting
|
|
s.sendall(json.dumps({"execute": "qmp_capabilities"}).encode() + b"\n")
|
|
s.recv(4096) # Capabilities accepted
|
|
cmd = json.dumps({"execute": "screendump", "arguments": {"filename": out_file}})
|
|
s.sendall(cmd.encode() + b"\n")
|
|
s.recv(4096) # Screendump completed
|
|
s.close()
|
|
print(f"Successfully captured screenshot to: {out_file}")
|
|
except Exception as e:
|
|
print(f"Failed to capture {out_file}: {e}")
|
|
|
|
if __name__ == "__main__":
|
|
if len(sys.argv) < 3:
|
|
print("Usage: capture_qemu.py <qmp_socket_path> <output_ppm_path>")
|
|
sys.exit(1)
|
|
sock = sys.argv[1]
|
|
out = sys.argv[2]
|
|
qmp_screendump(sock, out)
|