zzzhhy
2014-11-18 10:18
采纳率: 0%
浏览 2.2k

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

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

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

3条回答 默认 最新

  • 91program 2014-11-18 10: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;
    

    }

    评论
    解决 无用
    打赏 举报
  • threenewbee 2014-11-18 10:25

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

    评论
    解决 无用
    打赏 举报
  • vinllen 2014-11-19 02:01

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

    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题