Finding your true computer name on the network

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

Tags: , , ,

One Response to “Finding your true computer name on the network”

  1. matef Says:

    My name is just “ubuntu” 🙂

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s


%d bloggers like this: