Skip to content

Instantly share code, notes, and snippets.

@0x2a94b5
Created July 20, 2020 11:42
Show Gist options
  • Save 0x2a94b5/3b265d74c07abe2708e676a5dad2ed63 to your computer and use it in GitHub Desktop.
Save 0x2a94b5/3b265d74c07abe2708e676a5dad2ed63 to your computer and use it in GitHub Desktop.
get hostname on windows
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# get local computer name on windows
# package: pyinstaller -y -F -c getHostname.py
#
from subprocess import run, PIPE
cmd = "C:\\Windows\\System32\\HOSTNAME.EXE"
process = run(cmd, shell=True, stdout=PIPE, universal_newlines=True)
hostname = process.stdout.strip()
print("hostname is %s" % hostname)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment