IP address of a website - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

IP address of a website

andrewgs73andrewgs73 Posts: 95Member
Hello,
How can i get the ip address of a website, say "www.yahoo.com".
Any comments is appreciated. Thanks a lot.
Regards,
Andrew

Comments

  • DB1DB1 Posts: 1,142Member
    : Hello,
    : How can i get the ip address of a website, say "www.yahoo.com".
    : Any comments is appreciated. Thanks a lot.
    : Regards,
    : Andrew
    :

    You'll want to look up sockets functions. Two lines of code will do it (plus the WSAStartup routine on windows), but you'll want to add error checking etc... You might want to also enum the h_addr_list instead of just h_addr_list[0] like in this example.
    [code]

    struct hostent *hostdata = gethostbyname( SomeWebsiteURL );

    char *IP = inet_ntoa( *(in_addr*)hostdata->h_addr );
    [/code]



    [italic][blue]To understand recursive, first you need to understand recursive[/blue][/italic]

  • andrewgs73andrewgs73 Posts: 95Member
    Thanks a lot. It worked on my PC which is directly connected
    on my ISP. However, it didn't worked out on my pc on the LAN
    in which the pc connects through a proxy server.
    Do you have idea on this?
    : : Hello,
    : : How can i get the ip address of a website, say "www.yahoo.com".
    : : Any comments is appreciated. Thanks a lot.
    : : Regards,
    : : Andrew
    : :
    :
    : You'll want to look up sockets functions. Two lines of code will do it (plus the WSAStartup routine on windows), but you'll want to add error checking etc... You might want to also enum the h_addr_list instead of just h_addr_list[0] like in this example.
    : [code]
    :
    : struct hostent *hostdata = gethostbyname( SomeWebsiteURL );
    :
    : char *IP = inet_ntoa( *(in_addr*)hostdata->h_addr );
    : [/code]
    :
    :
    :
    : [italic][blue]To understand recursive, first you need to understand recursive[/blue][/italic]
    :
    :

Sign In or Register to comment.