Python get device-name

16.6k views Asked by At

im not new in Python but I have one question left: How do I get the name of the Computer that im on/Device ? I tried many things, this is the last thing, I was in the os Module and found something but if i start the script, it gives me an error that in the os module isn't a 'getDeviceName' function.

from os import *

os.getDeviceName()
3

There are 3 answers

0
SAStephen421 On

CMD:

echo %USERNAME% > ["drive"]:\["path"]\["filename"].["extension"]

example:

echo %USERNAME% > C:\username.uf

python:


path = open("C:\\username.uf", 'r')

username = path.readlines()

print(username)

Console:

['"your username will display here" /n']

if u don't want this '/n' then u can replace it... i know this will take some extra time but for me this is good cuz ima begginer but i learned some other things to print it just by using python

0
Tim On
import socket
socket.gethostname()

would also work just fine.

1
Corey Goldberg On

to get the machine name, see platform.node(): https://docs.python.org/3/library/platform.html#platform.node

example:

import platform
print(platform.node())