How to get Computer Name given IP address?

  • Thread starter Thread starter RussR
  • Start date Start date
R

RussR

Hi,

I'm writing a program on my xpe computer that is running on a network and it
has to "discover"
the names of the other computers on the network in that same workgroup. The
good thing is that it knows all the IP addresses of the computers on the
network for which it wants the names. Is there a function that will allow
me to do this?

I'm aware of this:
BOOL GetComputerName(
LPTSTR lpBuffer, // address of name buffer
LPDWORD nSize // address of size of name buffer
);

It is however only useful on the computer where my code runs, not for
getting the names of the others.

The network is a regular Client For MS Networks with Workgroup (No Domain)
running. The systems will all be headless.

Thanks,
RussR
 
RussR,

You basically need to do reverse lookup for component names.
Have you tried nslookup.exe tool? ("Command Line DNS Query Utility" component).

gethostbyaddr API is what you probably looking for if you need NetBIOS names. Search MSDN for more info on the function.
 
nslookup doesn't work

gethostbyaddr() looked like exactly what i wanted, but i couldn't get it
work. it always returned null and the error that it returned to
WSAGetLastError() was = 1 which was not defined in the docuemntation.

Any ideas?
 
RussR,
nslookup doesn't work

What problems were there?
Did you monitor the tool with Filemon/Regmon?
gethostbyaddr() looked like exactly what i wanted, but i couldn't get it work. it always returned null and the error that it
returned to WSAGetLastError() was = 1 which was not defined in the docuemntation.

Wierd error code (all WSA error codes should be with 10000 basis).
Did you call WSAStartup first?
I assume the "Windows Sockets" and "TCP/IP Networking" components are in your image with all dependencies resolved.
Also, make sure "Primitive: Iphlpapi" and "Windows Firewall/Internet Connection Sharing (ICS)" included.

You will also need toturn off firewall on the image (at least for testing purposes).
 
Ok, I had forgotten to call WSAStartup, so now I did, but I'm still having
problems. BTW, i'm developing on a XP Pro machine w/o any firewall.

Here's my code:
remoteHost=gethostbyaddr((const
char*)inet_addr("192.168.111.3"),sizeof(long),AF_INET);
int error=WSAGetLastError();
if (WSAGetLastError() != 0) {
if (error == 11001)
printf("Host not found...\nExiting.\n");
}
if (remoteHost != NULL)
printf("%s\n",remoteHost->h_name);
I get an access violation error message right after gethostaddr() gets
called.
 
nevermind, should have been this:
gethostbyaddr( (char*) &inet_addr("192.168.111.3\0"), sizeof(long),
AF_INET);

thanks again KM
 
Ok, I've got another question for you regarding LPSHFILEOPSTRUCT.
here's what I have:
LPSHFILEOPSTRUCT fileop;
fileop->hwnd= NULL;
fileop->wFunc=FO_MOVE;
fileop->pFrom=copyPath.c_str();
fileop->pTo="c:\\Data";
fileop->fFlags=FOF_SILENT | FOF_NOCONFIRMMKDIR | FOF_NOCONFIRMATION;

I'm experiencing a problem in that hwnd is a pointer to a dialog window and
I don't know what to give it since my code is in a command line app. Any
ideas?

Thanks,
RussR
 
Replied you in another (original) thread.

Btw, you don't necessarily have to provide "dialog" window handle. It could be any window owner handle that can be a parent to the
shell progress dialog box.
 
Yeah sorry, I posted in the wrong thread, this belongs in the "Moving Files
Over the Network Through a Program" thread.
 
Back
Top