欢迎来到 嗅灵易学

零基础也能上手的脚本技术课,一对一答疑带你入门

简单获取外网IP地址

简单获取外网IP地址

#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,"http://www.baidu.com/s?wd=ip",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;
}

注意:上传附件及图片大小不得大于30M。

⚠️ 版权声明:
本博客所有内容(含教程、源码、工具)仅供个人技术学习与研究交流使用,严禁商用、倒卖、二次分发及非法用途。
未经作者书面授权,任何组织或个人不得转载、复制或用于其他平台,违者将追究相关责任。

0 0 0 举报
复制成功