PDA

View Full Version : Getting the ip address of web sites?



Nutshell
03-16-2002, 04:57 AM
Hi,

Say i've got a web site address, how do i find out its ip address?

thnx

maes
03-16-2002, 05:43 AM
try gethostbyname()



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


Do not forget to include the wsock32.lib library

I copy pasted this out of a program of mine, it is possible I fergot something (hope not)


thx Fordy ;)

(TNT)
03-16-2002, 05:58 AM
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

Fordy
03-16-2002, 05:59 AM
Yeah....and if you want it to run it as a single program;



/////////////////////////////
// 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;
}

no-one
03-16-2002, 08:47 PM
its called tracert.

ober
03-17-2002, 07:50 PM
Originally posted by no-one
its called tracert.

that's gotta be the coolest thing i've seen.... why haven't i found that before now?!?! :eek:

novacain
03-18-2002, 12:16 AM
You haven't been paying attention.

http://www.telstra.net.au/cgi-bin/trace online tracer