免费试用:最火的人工智能查询工具
     最强AI人工智能聊天工具
     对话机器人解答疑难问题
星外智问直连原始API接口(GPT-4o)
➡️未登录受限条数,请登陆使用完整服务>>>➡️
请输入您要问的问题:


查下百度  查下必应

以下是单个问题的回复:

问:c++获取windows网卡内网IP去除0.0.0.0和169.254开头的IP,返回数据类型为string
GPT答: 7i24.cn
//方法一:
#include <windows.h>
#include <winsock2.h>
#include <iphlpapi.h>
#include <stdio.h>
#include <string>
#pragma comment(lib, "IPHLPAPI.lib")

std::string getIPAddress()
{
    std::string ret;
    PIP_ADAPTER_INFO pAdapterInfo;
    PIP_ADAPTER_INFO pAdapter = NULL;
    DWORD dwRetVal = 0;
    UINT i;

    ULONG ulOutBufLen = sizeof(IP_ADAPTER_INFO);
    pAdapterInfo = (IP_ADAPTER_INFO *)malloc(sizeof(IP_ADAPTER_INFO));
    if (pAdapterInfo == NULL) {
        return "";
    }

    if (GetAdaptersInfo(pAdapterInfo, &ulOutBufLen) == ERROR_BUFFER_OVERFLOW) {
        free(pAdapterInfo);
        pAdapterInfo = (IP_ADAPTER_INFO *)malloc(ulOutBufLen);
        if (pAdapterInfo == NULL) {
            _endthread();
            return "";
        }
    }
    if ((dwRetVal = GetAdaptersInfo(pAdapterInfo, &ulOutBufLen)) == NO_ERROR) {
        pAdapter = pAdapterInfo;
        while (pAdapter) {
            if (pAdapter->Type != MIB_IF_TYPE_ETHERNET) {
                pAdapter = pAdapter->Next;
                continue;
            }
            IP_ADDR_STRING *pIpAddrStr = &(pAdapter->IpAddressList);
            do {
                if (strcmp(pIpAddrStr->IpAddress.String, "0.0.0.0") != 0) {
                    std::string ipStr(pIpAddrStr->IpAddress.String);
                    if(ipStr.find("169.254") != std::string::npos) {  
                        pIpAddrStr = pIpAddrStr->Next;  
                        continue;  
                    }  
                    ret = ipStr;
                    break;
                }
                pIpAddrStr = pIpAddrStr->Next;
            } while (pIpAddrStr);

            if (!ret.empty())
                break;

            pAdapter = pAdapter->Next;
        }
        free(pAdapterInfo);
    }
    return ret;
}

//方法二
#include<WinSock2.h>
#include<WS2tcpip.h>
#include<Iphlpapi.h>
#include<Windows.h>
#include<string>

std::string getLocalIP()
{
    char szHostName[255] = {0};
    char szLocalIP[255] = {0};
    gethostname(szHostName, sizeof(szHostName));
    HOSTENT *host;
    host = gethostbyname(szHostName);
    for(int i = 0; host->h_addr_list[i]; i++)
    {
        inet_ntop(AF_INET, host->h_addr_list[i], szLocalIP, sizeof(szLocalIP));
        std::string ipStr = szLocalIP;
        if(ipStr.find("169.254") != std::string::npos) {  
            continue;  
        }   
        return ipStr;
    } 
    return 0;
}
一星  二星  三星  四星  五星 

互联网非法外之地,请不要输入不良内容
 查下百度 查下必应 02-22 16:19:07



chatGPT中国版--星外智问--8v6.CN
当前运行网址:haoadm.com
客服微信:xwgdd_com APP下载 怎么问 识别真假GPT4 使用GPT赚钱 退出登陆