Skip to content

Instantly share code, notes, and snippets.

@billywhizz
Forked from stefano-garzarella/vsock-get-cid.py
Created July 14, 2025 00:36
Show Gist options
  • Save billywhizz/5ede32a8b8ebf9c57cdc9349f1e9d298 to your computer and use it in GitHub Desktop.
Save billywhizz/5ede32a8b8ebf9c57cdc9349f1e9d298 to your computer and use it in GitHub Desktop.
vsock: get local CID using the available ioctl
#!/usr/bin/env python3
import socket
import struct
import fcntl
with open("/dev/vsock", "rb") as fd:
r = fcntl.ioctl(fd, socket.IOCTL_VM_SOCKETS_GET_LOCAL_CID, " ")
cid = struct.unpack("I", r)[0]
print("Local CID: {}".format(cid))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment