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