473,322 Members | 1,806 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

how to get IP address of computer given its name

how can I get the IP address of a computer when I only know its computername
in a windows network?

--
cody

[Freeware, Games and Humor]
www.deutronium.de.vu || www.deutronium.tk
Nov 17 '05 #1
1 6362
>how can I get the IP address of a computer when I only know its computername
in a windows network?


Here's an example doctored from Knowledge Base article 183988 "HOWTO:
Retrieve the IP Address of the Remote PPP Peer":

DWORD GetIpAddress(char *hostname)
{
DWORD dwIP = 0;

TCHAR msg[128];
HOSTENT *lpHost=NULL;
struct sockaddr_in dest;

lpHost = gethostbyname(hostname);
if (lpHost == NULL)
{
wsprintf(msg, _T("gethostbyname failed: %d"),
WSAGetLastError());
MessageBox(NULL, msg, NULL, MB_OK);
}
else
{
for(int i=0; lpHost->h_addr_list[i] != NULL ;i++)
{
memcpy(&(dest.sin_addr),
lpHost->h_addr_list[i],
lpHost->h_length);
dwIP = ntohl( dest.sin_addr.S_un.S_addr );
}

}

return dwIP;
}

Dave
--
MVP VC++ FAQ: http://www.mvps.org/vcfaq
Nov 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Homer | last post by:
How can I obtain the client IP address or machine name from within an asp.net application? I want to use this information to determine where to redirect a web page. Many thanks Homer
1
by: techprot-google04 | last post by:
I've found tons of sample code on pinging - but all start with the host name, resolve the ip address and do the ping. Does anyone have any sample code that does a ping from an ip address alone?...
4
by: rdonnici | last post by:
Hi all, Is there any way to, given an IP address(or NETBIOS machinename - I can convert from one to other) from my network, and assuming that everyone needs to log on a NT/2K/Windows Server 2003...
1
by: ruca | last post by:
hi, Can Anyone tell me or indicate some sites to get information, what's the differences between calling my Web Application with an Ip Address or the Server Name??? Example: Ip Address...
0
by: sasidar.d | last post by:
hi techies I have created a Login web page . It gets the user identity using the window nt authetication. The page is working fine. I have removed the allow anonymous access check box for the...
1
by: umesh049 | last post by:
Hello A check constraint SYS_C0011712 is system given name to the constraint but when i want to disable it. i can' t it please give me some solution. thanks SQL> SELECT CONSTRAINT_NAME,...
0
by: kashok | last post by:
hi all, how to track online visitors ip address and country name through ip address of those who are visiting my web site in asp.net..... Ashok
11
jsos20
by: jsos20 | last post by:
a subroutine that creates a file with a given name and outputs the contents of a array to given named file It should be called in the following way: &WriteToFile(``suppliers.txt'', @suppliers);...
3
by: pizzaface | last post by:
Hello: I'm wanting to update a Microsoft Access Table automatically with the network computer name and user name as soon as a user logs onto his/her computer. I would like this to happen with...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.