Posts Tagged ‘network’

Finding your true computer name on the network

October 13, 2009

In many cases, it is essential to find the name of a computer over a local network. Such fits well when on a DHCP network, and need to always reach a certain machine.

An easy way to obtain this data, is via the python socket library. The ip of the desired machine is obtained via ipconfig (windows) or ifconfig (linux). For the sake of the example, assume that the ip from the DHCP network is 10.0.0.5.

In the python interpretor, execute the following code:

import socket
true_name = socket.gethostbyaddr("10.0.0.5")[0]
print true_name

The code above prints the true name of the machine, as seen on the network. This name is not always the machine name. For example the machine name could be “saher-desktop”, while the name on the network is “saher-desktop.local”.

Advertisements

%d bloggers like this: