如何得到本机的真实IP?

解决方案 »

  1.   

    添加一个WINSOCK控件
    在一个窗体上添加一个textPrivate Sub Form_Load()  Text1.Text = Winsock1.LocalIPEnd Sub
      

  2.   

    WINSOCK(大宝)挺好的,我一直在用它。
      

  3.   

    用Winsock1.LocalIP 方法得到的IP作为服务器,客户端如果连接这个IP为什么连不到阿.
      

  4.   

    用那个得到的是内网ip吧
    你要在哪里通信呀
    哪个不是真实的ip吧
      

  5.   

    要做的是个在internet上通信的程序,
    如何得到本机的真实IP?
      

  6.   

    http://www.linkwan.com/gb/broadmeter/
    这个网站能追中到你的地址 traceroute 这个命令可以看到路径!!!!!你可以分析那个是你的外部地址 
    你试试
      

  7.   

    添加一个WINSOCK控件?怎么添加? 
    不好意思,不知道是哪一个!:)
      

  8.   

    工程-》部件-》microsoft winsock control6.0
      

  9.   

    红松 搞定了吗? 可以把你的原码发给我吗?
    my e-mail:[email protected]
      

  10.   

    #include <windows.h>
    #include <iphlpapi.h>
    #include <stdio.h>
    #include <time.h>void main(void) {    DWORD Err;    PFIXED_INFO pFixedInfo;
        DWORD FixedInfoSize = 0;    PIP_ADAPTER_INFO pAdapterInfo, pAdapt;
        DWORD AdapterInfoSize;
        PIP_ADDR_STRING pAddrStr;    //
        // Get the main IP configuration information for this machine using a FIXED_INFO structure
        //
        if ((Err = GetNetworkParams(NULL, &FixedInfoSize)) != 0)
        {
            if (Err != ERROR_BUFFER_OVERFLOW)
            {
                printf("GetNetworkParams sizing failed with error %d\n", Err);
                return;
            }
        }    // Allocate memory from sizing information
        if ((pFixedInfo = (PFIXED_INFO) GlobalAlloc(GPTR, FixedInfoSize)) == NULL)
        {
            printf("Memory allocation error\n");
            return;
        }    if ((Err = GetNetworkParams(pFixedInfo, &FixedInfoSize)) == 0)
        {
            printf("\tHost Name . . . . . . . . . : %s\n", pFixedInfo->HostName);
            printf("\tDNS Servers . . . . . . . . : %s\n", pFixedInfo->DnsServerList.IpAddress.String);
            pAddrStr = pFixedInfo->DnsServerList.Next;
            while(pAddrStr)
            {
                printf("%52s\n", pAddrStr->IpAddress.String);
                pAddrStr = pAddrStr->Next;
            }        printf("\tNode Type . . . . . . . . . : ");
            switch (pFixedInfo->NodeType)
            {
                case 1:
                    printf("%s\n", "Broadcast");
                    break;
                case 2:
                    printf("%s\n", "Peer to peer");
                    break;
                case 4:
                    printf("%s\n", "Mixed");
                    break;
                case 8:
                    printf("%s\n", "Hybrid");
                    break;
                default:
                    printf("\n");
            }        printf("\tNetBIOS Scope ID. . . . . . : %s\n", pFixedInfo->ScopeId);
            printf("\tIP Routing Enabled. . . . . : %s\n", (pFixedInfo->EnableRouting ? "yes" : "no"));
            printf("\tWINS Proxy Enabled. . . . . : %s\n", (pFixedInfo->EnableProxy ? "yes" : "no"));
            printf("\tNetBIOS Resolution Uses DNS : %s\n", (pFixedInfo->EnableDns ? "yes" : "no"));
        } else
        {
            printf("GetNetworkParams failed with error %d\n", Err);
            return;
        }    //
        // Enumerate all of the adapter specific information using the IP_ADAPTER_INFO structure.
        // Note:  IP_ADAPTER_INFO contains a linked list of adapter entries.
        //
        AdapterInfoSize = 0;
        if ((Err = GetAdaptersInfo(NULL, &AdapterInfoSize)) != 0)
        {
            if (Err != ERROR_BUFFER_OVERFLOW)
            {
                printf("GetAdaptersInfo sizing failed with error %d\n", Err);
                return;
            }
        }    // Allocate memory from sizing information
        if ((pAdapterInfo = (PIP_ADAPTER_INFO) GlobalAlloc(GPTR, AdapterInfoSize)) == NULL)
        {
            printf("Memory allocation error\n");
            return;
        }    // Get actual adapter information
        if ((Err = GetAdaptersInfo(pAdapterInfo, &AdapterInfoSize)) != 0)
        {
            printf("GetAdaptersInfo failed with error %d\n", Err);
            return;
        }    pAdapt = pAdapterInfo;    while (pAdapt)
        {
            switch (pAdapt->Type)
            {
                case MIB_IF_TYPE_ETHERNET:
                    printf("\nEthernet adapter ");
                    break;
                case MIB_IF_TYPE_TOKENRING:
                    printf("\nToken Ring adapter ");
                    break;
                case MIB_IF_TYPE_FDDI:
                    printf("\nFDDI adapter ");
                    break;
                case MIB_IF_TYPE_PPP:
                    printf("\nPPP adapter ");
                    break;
                case MIB_IF_TYPE_LOOPBACK:
                    printf("\nLoopback adapter ");
                    break;
                case MIB_IF_TYPE_SLIP:
                    printf("\nSlip adapter ");
                    break;
                case MIB_IF_TYPE_OTHER:
                default:
                    printf("\nOther adapter ");
            }
            printf("%s:\n\n", pAdapt->AdapterName);        printf("\tDescription . . . . . . . . : %s\n", pAdapt->Description);         printf("\tPhysical Address. . . . . . : ");
            for (UINT i=0; i<pAdapt->AddressLength; i++)
            {
                if (i == (pAdapt->AddressLength - 1))
                    printf("%.2X\n",(int)pAdapt->Address[i]);
                else
                    printf("%.2X-",(int)pAdapt->Address[i]);
            }                printf("\tDHCP Enabled. . . . . . . . : %s\n", (pAdapt->DhcpEnabled ? "yes" : "no"));        pAddrStr = &(pAdapt->IpAddressList);
            while(pAddrStr)
            {
                printf("\tIP Address. . . . . . . . . : %s\n", pAddrStr->IpAddress.String);
                printf("\tSubnet Mask . . . . . . . . : %s\n", pAddrStr->IpMask.String);
                pAddrStr = pAddrStr->Next;
            }        printf("\tDefault Gateway . . . . . . : %s\n", pAdapt->GatewayList.IpAddress.String);
            pAddrStr = pAdapt->GatewayList.Next;
            while(pAddrStr)
            {
                printf("%52s\n", pAddrStr->IpAddress.String);
                pAddrStr = pAddrStr->Next;
            }        printf("\tDHCP Server . . . . . . . . : %s\n", pAdapt->DhcpServer.IpAddress.String);
            printf("\tPrimary WINS Server . . . . : %s\n", pAdapt->PrimaryWinsServer.IpAddress.String);
            printf("\tSecondary WINS Server . . . : %s\n", pAdapt->SecondaryWinsServer.IpAddress.String);        struct tm *newtime;        // Display coordinated universal time - GMT 
            newtime = gmtime(&pAdapt->LeaseObtained);   
            printf( "\tLease Obtained. . . . . . . : %s", asctime( newtime ) );        newtime = gmtime(&pAdapt->LeaseExpires);   
            printf( "\tLease Expires . . . . . . . : %s", asctime( newtime ) );        pAdapt = pAdapt->Next;
        }
    }
      

  11.   

    kernel32.lib
    libcmt.lib
    wsock32.lib
    iphlpapi.lib
      

  12.   

    http://www.fantasiasoft.net/Source/GetIPAddress.zip
      

  13.   

    to: joyous(SAKER)  有没有vb的代码阿,我要的不是C
    =========================
    to: thirdapple(陨落雕) 你的代码还是不能解决我的问题(还是没能得到本机真实的IP)不过还是谢谢两位兄台!!***********************************
    *还有没有人知道阿,还请各位帮忙!!!*
    ***********************************
      

  14.   

    我有代码请与我联系!
    [email protected]
      

  15.   

    有一个办法就是,建一个网页,让程序访问那个显IP的网页,然后将IP返回给程序.
      

  16.   

    还是只显示adsl上的IP和本机内部IP,找不到真正外部Internet的IP
      

  17.   

    http://www.usawww.net/vb/MyIP.rar
    有問題請與我聯系.
    email:[email protected]
      

  18.   

    我这有个控件,叫网络定位器(FFGPS)
    注册一个帐号,登录该帐号,查询该帐号的地址,就可以得到你的实际地址.
    http://www.offca.com/ffca/down/rar/ffgps.rar
    ----------------------------------------------- 
    我编了三年程序       只用过VB 
    我用了三年VB         只用过WINSOCK 
    我用了三年WINSOCK    只用过UDP和TCP 
    我用了三年UDP和TCP   原来都用的是TCP/IP协议 
    http://www.offca.com/gps/iphonebbs/
    **********中国网络程序开发联盟欢迎你**********
    -----------------------------------------------
      

  19.   

    winsock那个只是ADSL得内部IP啊~