-
-
[原创]简单获取外网IP地址
-
发表于:
2011-12-14 21:32
6247
-
#include "stdafx.h"
#include "获取外网IP地址.h"
#include <WININET.H>
#pragma comment(lib,"Wininet.lib")
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// The one and only application object
CWinApp theApp;
using namespace std;
//////////////////////////////////////////////
char * getip()
{
static char Add[256];
HINTERNET hit=InternetOpen("ie",INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
if(hit)
{
HINTERNET hIurl = InternetOpenUrl(hit,"f3cK9s2c8@1M7q4)9K6b7g2)9J5c8W2)9J5c8Y4N6%4N6#2)9J5k6h3u0S2K9h3c8#2i4K6u0W2j5$3!0E0i4K6u0r3M7#2)9K6c8Y4N6V1i4K6y4p5K9i4l9`.",NULL,-1,0,0);
if(hIurl)
{
char buf[100000];
memset(buf,0,100000);
DWORD dwR=0;
if(InternetReadFile(hIurl,buf,100000,&dwR))
{
char * s=buf;
char * s1=strstr(s,"本机IP: <strong>");
s1=s1+21;
char * s2=strstr(s1,"</strong> ");
int count=s2-s1;
strncpy(Add,s1,count);
}
else
{
strcpy(Add,"");
}
}
else
{
strcpy(Add,"");
}
}
else
{
strcpy(Add,"");
}
return Add;
}
int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
int nRetCode = 0;
CString strHello=getip();
cout << (LPCTSTR)strHello << endl;
return nRetCode;
}
[培训]科锐逆向工程师培训第53期2025年7月8日开班!