2 zzzhhy zzzhhy 于 2014.11.18 18:18 提问

我想通过软件,获取本机外网ip地址,然发送给web服务器跳转,类似花生壳

我想通过写一个软件,每天开机的时候获取本机外网ip地址,然发送给web服务器做跳转,类似花生壳,这样其他人就可以通过访问web服务器,就可以跳转到我的ip对应的网站,这个请问要怎么实现呢,谢谢回答!

3个回答

caozhy
caozhy   Ds   Rxr 2014.11.18 18:25

外网地址必须借助外网服务器才能获取(当然你可以用现成的服务器,比如ip138),另外,开机的时候获取是不够的,因为ip变动并不和开机有关,你的dhcp租期到了,或者网络断开重连都会更换ip,最后,大陆电信运营商基本都封掉了80端口,这使得你就是报告了ip,人家也连不上,综上,还是花个几十块钱,买个vps,托管你的网站比较有实际意义。

zzzhhy
zzzhhy 谢谢你的回复,不过我们是应用不需要80端口,买云服务器要一年8000多
大约 3 年之前 回复
u011353822
u011353822   2014.11.19 10:01

外网ip是可以获取,但你得在你的出口路由上做DNAT转发,或者你本身具有公网ip,花生壳应该也是有个外网的服务器做解析的

91program
91program   Ds   Rxr 2014.11.18 18:21

VC 代码:
BOOL GetNetworkInfoTemp(pOne_Adapter_Info pOneAdapterInfo,char *pcOneDesc)
{
PIP_ADAPTER_INFO pAdapterInfo;
PIP_ADAPTER_INFO pAdapter = NULL;
DWORD dwRetVal = 0;

pAdapterInfo = (IP_ADAPTER_INFO *) malloc( sizeof(IP_ADAPTER_INFO) );
ULONG ulOutBufLen = sizeof(IP_ADAPTER_INFO);

// Make an initial call to GetAdaptersInfo to get
// the necessary size into the ulOutBufLen variable
if (GetAdaptersInfo( pAdapterInfo, &ulOutBufLen) == ERROR_BUFFER_OVERFLOW) {
    free(pAdapterInfo);
    pAdapterInfo = (IP_ADAPTER_INFO *) malloc (ulOutBufLen); 
    if (pAdapterInfo == NULL) {
        TRACE("Error allocating memory needed to call GetAdaptersinfo\n");
        return 1;
    }

    if ((dwRetVal = GetAdaptersInfo( pAdapterInfo, &ulOutBufLen)) == NO_ERROR)
    {
        pAdapter = pAdapterInfo;
        while (pAdapter)
        {
            if(NULL != pcOneDesc && NULL != pOneAdapterInfo)
            {
                if(0 == strncmp(pcOneDesc,pAdapter->Description,strlen(pcOneDesc)))
                {
                    ZeroMemory(pOneAdapterInfo,sizeof(One_Adapter_Info));

                    strcpy(pOneAdapterInfo->AdapterName,pAdapter->AdapterName);
                    strcpy(pOneAdapterInfo->Description,pAdapter->Description);
                    pOneAdapterInfo->AddressLength = pAdapter->AddressLength;
                    memcpy(pOneAdapterInfo->Address,pAdapter->Address,sizeof(char) * (MAX_ADAPTER_ADDRESS_LENGTH));
                    pOneAdapterInfo->IpAddressList = pAdapter->IpAddressList;
                    pOneAdapterInfo->GatewayList = pAdapter->GatewayList;
                }
            }

            TRACE("\tAdapter Name: \t%s\n", pAdapter->AdapterName);
            TRACE("\tAdapter Desc: \t%s\n", pAdapter->Description);
            TRACE("\tAdapter Addr: \t");
            for (UINT i = 0; i < pAdapter->AddressLength; i++) {
                if (i == (pAdapter->AddressLength - 1))
                    TRACE("%.2X\n",(int)pAdapter->Address[i]);
                else
                    TRACE("%.2X-",(int)pAdapter->Address[i]);
            }
            TRACE("\tIP Address: \t%s\n", pAdapter->IpAddressList.IpAddress.String);
            TRACE("\tIP Mask: \t%s\n", pAdapter->IpAddressList.IpMask.String);

            TRACE("\tGateway: \t%s\n", pAdapter->GatewayList.IpAddress.String);
            TRACE("\t***\n");

            if (pAdapter->DhcpEnabled)
            {
            }
            pAdapter = pAdapter->Next;
        }
        free(pAdapterInfo);
    }
    return TRUE;
}

return FALSE;

}

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!