Howdy, Stranger!

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

Sign In with Facebook Sign In with Google Sign In with OpenID

Categories

We have migrated to a new platform! Please note that you will need to reset your password to log in (your credentials are still in-tact though). Please contact lee@programmersheaven.com if you have questions.
Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

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.