0

Im building an application that contacts with local hosts, instead of asking or showing the IP address and letting the user to interact with the ip, I wanted to show the device name directly.

Is there any way to do that?

I only could do that with other applications but not with python.

I searched in socket and in many other modules but I did not find the solution, maybe is it impossible?

wido
  • 3
  • 3

2 Answers2

0

Given an IP address the function socket.gethostbyaddr() returns a tuple containing:

  • Host Name
  • Alias list for the IP address if any
  • IP address of the host

Docs: https://docs.python.org/3/library/socket.html#socket.gethostbyaddr

MattDMo
  • 100,794
  • 21
  • 241
  • 231
iohans
  • 838
  • 1
  • 7
  • 15
-1

That should be possible as following:

import socket
socket.gethostbyaddr("69.59.196.211")

resource: https://stackoverflow.com/a/2575779/20443541

kaliiiiiiiii
  • 925
  • 1
  • 2
  • 21
  • Don't answer a question simply with a link to another Stack Overflow question or answer. If an answer to another question solves the asker's problem, then the question is a duplicate and should be flagged as such. Use the `Flag` link under the question's text and look for the "Duplicate" option. – MattDMo Jan 19 '23 at 19:01
  • Well then it is a dublicate. I still think providing the answer, even if it is a dublicate should be valid. – kaliiiiiiiii Jan 19 '23 at 19:13
  • 1
    From [How Do I Write a Good Answer?](https://stackoverflow.com/help/how-to-answer) in the [help], *`Not all questions can or should be answered here. Save yourself some frustration and avoid trying to answer questions which... have already been asked and answered many times before.`* Please also read [Your answer is in another castle: when is an answer not an answer?](https://meta.stackexchange.com/q/225370). – MattDMo Jan 19 '23 at 22:59