#include "stdafx.h"
#include <stdio.h>
#include <winsock.h>
#include <windows.h>
#include <string.h>
void main()
{
struct hostent *thishost;
struct in_addr in;
char MYName[80];
char *Ptr;
WORD wVersionRequested;
WSADATA wsaData;
int err;
int i,n; //循环变量
wVersionRequested = MAKEWORD (2, 0) ; // set winsock version
err = WSAStartup (wVersionRequested, & wsaData ); // enable winsock support (winsock increase the reference count)
IF (ERR = 0!)
{
Exit (0);
}
the gethostname ( MYName, 80); // get the host name
thishost = gethostbyname (MYName); // get the host information (IP, etc.)
memset ((void *) & in, sizeof (in), 0);
// get the number of cycles (IP number of addresses)
n-= strlen (* thishost-> the h_addr_list);
n-n-= / 2;
for(i=0;i<n;i++)
{
in.s_addr = *((unsigned long *)thishost->h_addr_list[i]);
Ptr = inet_ntoa(in);
printf("IP地址%d:%s",i+1,Ptr);
}
WSACleanup (); // winsock unload the dynamic library (reducing the reference count)
}
Original: https: //blog.csdn.net/paopaoc/article/details/562447