首页
社区
课程
招聘
[原创]简单获取外网IP地址
发表于: 2011-12-14 21:32 6247

[原创]简单获取外网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日开班!

收藏
免费 6
支持
分享
最新回复 (5)
雪    币: 370
活跃值: (15)
能力值: ( LV9,RANK:170 )
在线值:
发帖
回帖
粉丝
2
查外部ip
c6fK9s2c8@1M7q4)9K6b7g2)9J5c8W2)9J5c8Y4N6%4N6#2)9J5k6h3W2H3x3e0x3^5i4K6u0W2j5$3!0E0i4K6u0r3K9i4m8K6z5q4)9J5k6h3q4K6M7l9`.`.
查指定ip
3e1K9s2c8@1M7q4)9K6b7g2)9J5c8W2)9J5c8Y4N6%4N6#2)9J5k6h3W2H3x3e0x3^5i4K6u0W2j5$3!0E0i4K6u0r3K9i4m8K6i4K6u0W2j5i4y4H3i4K6y4r3K9i4m8Q4x3@1b7J5x3e0u0Q4x3X3f1$3y4W2)9J5k6e0p5@1x3q4)9J5k6i4S2^5P5q4)9J5y4X3q4U0N6r3W2G2L8W2)9K6c8o6t1`.
2011-12-15 10:47
0
雪    币: 452
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
3
9b5K9s2c8@1M7q4)9K6b7g2)9J5c8W2)9J5c8Y4N6%4N6#2)9J5k6h3W2H3i4K6u0W2j5$3&6Q4x3V1k6Q4x3@1k6S2j5%4c8A6L8$3&6Q4x3@1c8I4N6h3g2J5P5h3W2H3i4K6t1$3K9i4m8Q4y4h3k6#2M7X3I4Q4x3@1c8Q4x3U0g2K6i4@1f1^5i4@1u0r3i4K6V1&6i4@1f1@1i4@1t1^5i4@1q4m8i4@1f1@1i4@1t1&6i4K6W2r3i4@1f1#2i4K6S2r3i4@1q4r3i4@1f1@1i4@1u0n7i4@1p5#2i4@1f1%4i4K6W2m8i4K6R3@1i4@1f1#2i4K6V1H3i4@1p5%4i4@1g2r3i4@1u0o6i4K6W2r3
2011-12-15 11:54
0
雪    币: 209
活跃值: (143)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
4
用百度不如用这个专用的:

f3bK9s2c8@1M7q4)9K6b7g2)9J5c8W2)9J5c8Y4N6%4N6#2)9J5k6h3W2H3x3e0x3^5i4K6u0W2j5$3!0E0i4K6u0r3K9i4l9J5j5$3W2@1P5g2)9J5k6h3q4K6M7l9`.`.
2011-12-15 12:27
0
雪    币: 128
活跃值: (27)
能力值: ( LV5,RANK:60 )
在线值:
发帖
回帖
粉丝
5
搜索网页代码特征定位的不太靠谱的感觉,
还是用一些有协议规范的,
比如stun.xten.com
STUN协议
2011-12-15 12:38
0
雪    币: 9
活跃值: (25)
能力值: ( LV3,RANK:20 )
在线值:
发帖
回帖
粉丝
6
mark一下,感谢分享
2011-12-15 20:07
0
游客
登录 | 注册 方可回帖
返回