Skip to content

Instantly share code, notes, and snippets.

@andrewjbennett
Created February 26, 2017 05:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andrewjbennett/2ebd06e9e99716c54425b98357af5fbf to your computer and use it in GitHub Desktop.
Save andrewjbennett/2ebd06e9e99716c54425b98357af5fbf to your computer and use it in GitHub Desktop.
Determine the resolution for a series of VNC ports.
"""
Determine the resolution for a series of VNC ports.
Andrew Bennett <andrew.bennett@unsw.edu.au>
Feb 2017
Implementing the protocol from the RFC6143 spec:
https://tools.ietf.org/html/rfc6143
Width and Height:
| No. of bytes | Type [Value] | Description
| 2 | U16 | framebuffer-width in pixels |
| 2 | U16 | framebuffer-height in pixels |
| 16 | PIXEL_FORMAT | server-pixel-format |
| 4 | U32 | name-length |
| name-length | U8 array | name-string
"""
import socket
ports = [5911, 5912, 5913, 5914, 5915, 5916]
def recvs(s):
recv = s.recv(1024)
return recv
def sends(s, text):
s.send(text)
def convert_wh(result):
return int(result[0:2].encode('hex'), 16), int(result[2:4].encode('hex'), 16)
for port in ports:
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(("vlab", port))
# print "ProtocolVersion Handshake"
recvs(s)
sends(s, 'RFB 003.008\n')
# print "Security Handshake"
recvs(s)
sends(s, '\x01\n')
# print "SecurityResult Handshake"
recvs(s)
# print "ClientInit"
sends(s, '\x01\n')
# print "ServerInit"
result = recvs(s)
width, height = convert_wh(result[0:4])
print "resolution for port %d is: %d x %d " % (port, width, height)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment