delphi & netbios

jorgitobush used Ask the Experts™

I would like to know if there is a way to obtain a machine name (netbios name) given its ip address in delphi. I tried with client and server socket but got nothing for the moment.
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Try this:

uses Winsock;

function GetRemoteHostName(IPAddr : string) : string;
  wsdata : TWSAData;
  he : PHostEnt;
  ip : TInAddr;            
  WSAStartup(MakeWord(1, 1), wsdata);
  ip.S_addr := inet_addr(PChar(IPAddr));
  he := gethostbyaddr(@ip.S_un_b, 4, AF_INET);        
  if he<>nil then
    Result := string(he.h_name)
    Result := IntToStr(WSAGetLastError);

Regards, Geo


I Apreciatte your answer but that function retrieves de host name as ping -a does, but doesn't return the machine name.
For example : ip : has a machine name of 'SERVER' but the host is . In this case, the function returns '', not 'SERVER'.                

check out the NetServerEnum and WNetEnumResource functions
CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

Hi all...

After looking for a while I finally found the answer...
Here it is:

To retreive netbios information from a remote machine (machine name, mac address, shares, users logged in and other resources) you must send an UDP packet to that machine (with ip address as input) and receive the response packet.
I did it with NMUDP control setting remote host to the target ip, remote port 137 and local port 137.
Well, I think that the result means that your PC has DNS defined which returns that info.

However, it's nice that you've found the answer yourself.

Regards, Geo
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
Post your closing recommendations!  No comment means you don't care.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial