-2

My host is 10.13.17.18 but my host name is getting some other value

import socket
print(socket.gethostname())
print(socket.gethostbyname(socket.gethostname()))

Host name

Is there any solution in python to get hostname

MattDMo
  • 100,794
  • 21
  • 241
  • 231
Ajay
  • 89
  • 6
  • You can try `platform` package and `hostname = platform.node()` – Bijay Regmi Apr 13 '23 at 13:19
  • 2
    If there is an answer, it's there: [Finding local IP addresses using Python's stdlib](https://stackoverflow.com/questions/166506/finding-local-ip-addresses-using-pythons-stdlib) – mkrieger1 Apr 13 '23 at 13:23

1 Answers1

-1
import subprocess

host = subprocess.getoutput("hostname")
print("host:",host)
Merav2110
  • 11
  • 3