Get the IP address of the website

Source: Internet
Author: User

There are many ways to get the IP address of a Web site, and the most common is to use the ping command in the cmd command, which is also the most commonly used network command

Use the ping command to format the IP address of the Web site: Ping + site domain name

such as the way to obtain the IP address of Baidu: Ping + www.baidu.com

Test results:

Open cmd


After entering ping www.baidu.com, click Enter


The IP address of the website can also be obtained by Winscoket programming method

Program code:

#include <stdio.h> #include <stdlib.h> #include <winsock2.h>//connection to the Winsock library #pragma comment (lib, "ws2_ 32.lib ") void Main () {    //Call Wsatartup Initialize Winsock library    wsadata wsadata;    :: WSAStartup (        Makeword (2,2),// Version number is 2.2        &wsadata        );    Char szhost[256];//holds the domain name or server name    printf ("Please enter the domain name that needs to be resolved:");    scanf ("%s", szhost);    Hostent *phost =:: gethostbyname (Szhost);//Get address information by hostname    ///A host may have multiple network cards, multiple IPs, and the following code outputs all IP addresses    in_addr addr;    for (int i=0;; i++)    {        //Get Address (network byte)        char *p = phost->h_addr_list[i];        if (NULL = = p)        {            break;//exit loop        }        //Copies the address to the IN_ADDR structure        memcpy (&addr. S_un. S_ADDR, p, phost->h_length);        Convert in_addr to host byte order        char *strip =:: Inet_ntoa (addr);        Print IP address        printf ("%s"%d IP addresses are:%s\n ", Szhost, I+1, StrIP);    }    System ("Pause");}

Execution Result:

Get the IP address of the website

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.