#include<stdio.h> //头文件,大家都会吧
#include<winsock2.h>
#pragma comment(lib,"ws2_32.lib")
void CheckIP(void)
{
WSADATA wsaData;
char name[155];
char *ip;
PHOSTENT hostinfo;
if ( WSAStartup( MAKEWORD(2,0), &wsaData ) == 0 ) {
if( gethostname ( name, sizeof(name)) == 0) {
if((hostinfo = gethostbyname(name)) != NULL) { //这些就是获得IP的函数
ip = inet_ntoa (*(struct in_addr *)*hostinfo->h_addr_list);
printf("%s/n",ip);
}
}
WSACleanup( );
} }
int main(void)
{
CheckIP();
return 0;
}
从网上找的哈~
![](http://www.programfan.com/club/image/emotions/1.gif)