Hi,
Say i've got a web site address, how do i find out its ip address?
thnx
Printable View
Hi,
Say i've got a web site address, how do i find out its ip address?
thnx
try gethostbyname()
Do not forget to include the wsock32.lib libraryCode:WSADATA wsa;
struct hostent *g_hostent;
struct in_addr MyAddr;
char IPnumber[100][100];
WSAStartup(MAKEWORD(2,2),&wsa);
g_hostent=gethostbyname("www.cprogramming.com");
for (i = 0; g_hostent->h_addr_list[i] != 0; ++i)
{ //get all IPs
SendDlgItemMessage(parglist->hwnd,parglist->idc,WM_SETTEXT,0,(LPARAM)GETIP);
memcpy(&MyAddr,g_hostent->h_addr_list[0],sizeof(in_addr)); //You cannot edit the hostent struct
strcpy(IPnumber[i],inet_ntoa(MyAddr));//make into IP
memset(&MyAddr,0,sizeof(in_addr)); //clean again before next iteration
}
WSACleanup( ); //free winsock resources
I copy pasted this out of a program of mine, it is possible I fergot something (hope not)
thx Fordy ;)
Or if you are talking generally, non programming then simply use ping in dos.
Do this:
c:\> ping yahoo.com
Then in the first line of the reply you will get somthing like this:
Pinging yahoo.com [216.115.109.7] with 32 bytes of data:
The IP :)
TNT
Yeah....and if you want it to run it as a single program;
Code://///////////////////////////
// Include the WS2_32.lib
//
//
#include <iostream>
using std::cout;
using std::cin;
using std::endl;
#include <string>
using std::string;
#include <winsock2.h>
int main(int argc, char *argv[])
{
WSAData wsaData;
struct hostent *ptrHE;
struct in_addr add;
string strHost;
if (WSAStartup(MAKEWORD(1, 1), &wsaData) != 0) {
cout << "Error";
return 1;
}
cout << "Enter the host name to query" << endl;
cin >> strHost;
ptrHE = gethostbyname(strHost.c_str());
if (ptrHE == NULL) {
cout << endl << "Could not find the host." << endl;
return 1;
}
for(int i = 0; ptrHE->h_addr_list[i] != 0; ++i) {
memcpy(&add, ptrHE->h_addr_list[i], sizeof(struct in_addr));
cout << endl << "IP Number " << i+1;
cout << ": " << inet_ntoa(add) << endl;
}
WSACleanup();
return 0;
}
its called tracert.
that's gotta be the coolest thing i've seen.... why haven't i found that before now?!?! :eek:Quote:
Originally posted by no-one
its called tracert.
You haven't been paying attention.
http://www.telstra.net.au/cgi-bin/trace online tracer