16,472
社区成员
发帖
与我相关
我的任务
分享
// MyIP.cpp : Defines the entry point for the console application.
// setting "Debug Multithreaded"
#include "stdafx.h"
#include <afx.h>
#include <winsock2.h>
#pragma comment(lib, "ws2_32.lib")
void CheckIp(void)
{
WORD wVersionRequested;
WSADATA wsaData;
char name[255];
CString myip;
PHOSTENT hostinfo;
wVersionRequested=MAKEWORD(2,0);
if(WSAStartup(wVersionRequested,&wsaData)==0)
{
if(gethostname(name,sizeof(name))==0)
{
if((hostinfo=gethostbyname(name))!=NULL)
{
LPCSTR myip=inet_ntoa(*(struct in_addr *)* hostinfo->h_addr_list);
printf("%s\n",myip);
}
}
WSACleanup();
}
}
//
int main(int argc, char* argv[])
{
CheckIp();
return 0;
}
vc6 win7 通过