Answer the question
In order to leave comments, you need to log in
How to determine the computer name from an IP address?
I have a "floating" ip in the domain, which can be statically assigned to any one computer in the local network. This is done out of necessity. This is done by hand. I wrote a "sensor" program that pings this address and shows in the tray whether this address is busy or not (like a traffic light - green - not busy, red - busy). This address is always assigned to the computer only. Accordingly, the computer has a name that I want to determine and display in the tooltip so that you can hover and see who has this address. I found that there are several ways to determine the name of the computer, for example:
Dns.GetHostEntry
[DllImport("Netapi32.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
public extern static IntPtr NetWkstaGetInfo(string servername, int level,
[DllImport("IpHlpApi.dll")]
[return: MarshalAs(UnmanagedType.U4)]
static extern int GetIpNetTable(IntPtr pIpNetTable, [MarshalAs(UnmanagedType.U4)] ref int pdwSize, bool bOrder);
But they also write that these methods do not give a 100% result in determining the computer name by ip. Therefore, I go through these methods in turn, when the previous method could not determine the computer name. But still there are situations when none of the methods determined the computer name. And I wouldn't worry too much about this if it weren't for the
nbtstat -a [ip] program,
which always finds the correct computer name when my methods fail. Can you tell me what else to use? Some function or library (running nbtstat - do not suggest).
Answer the question
In order to leave comments, you need to log in
In a peer-to-peer network, when the computer is turned on, it sends a broadcast request over UDP (ports 137-139,445), notifying everyone that it has turned on. Those answer him who has what IP.
Listen to the broadcast packet and you will be happy, you can also ask other computers to respond by sending a broadcast request.
Perhaps I did not understand the essence of your question,
If there is netbios on the network, then it is enough
under Windows
under Linuxhost "проверяемый IP"
The name of the computer is transmitted by two protocols: SMB and DNS. Having studied their principle will be sufficient to understand the essence of your question.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question