Skip to content

Instantly share code, notes, and snippets.

@koss822
Last active August 11, 2022 07:27
Show Gist options
  • Save koss822/958c6344f29ee5d360abaceb16576e7c to your computer and use it in GitHub Desktop.
Save koss822/958c6344f29ee5d360abaceb16576e7c to your computer and use it in GitHub Desktop.
Detect active RDP connection in Python
from subprocess import check_output, STDOUT, CREATE_NO_WINDOW
def rdp_connected(self, ttl_hash=None):
output = check_output('qwinsta', stderr=STDOUT,
creationflags=CREATE_NO_WINDOW).decode('latin1')
for line in output.split('\r\n'):
if 'rdp-tcp#' in line and 'Active' in line:
log.info(line)
return True
return False
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment