Monday, April 21, 2025

Get the System Hostname using Python - gethostname()

import socket

print(socket.gethostname())

This code uses the socket module to print the hostname of the machine it is run on.

Explanation:

  1. import socket imports the socket module.

  2. socket.gethostname() returns a string representing the hostname of the current machine.

  3. print(socket.gethostname()) prints the hostname on the console.

No comments:

Post a Comment

Tkinter Introduction - Top Widget, Method, Button

First, let's make shure that our tkinter module is working ok with simple  for loop that will spawn 5 instances of blank Tk window .  ...