VC 获取IP host name

来源:互联网 发布:mac安装jdk后如何配置 编辑:程序博客网 时间:2024/06/16 04:15
    char    HostName[100];
    gethostname(HostName, sizeof(HostName));// 获得本机主机名.
    this->m_host_name.SetWindowTextA(HostName);

    hostent* hn;
    hn = gethostbyname(HostName);//根据本机主机名得到本机ip

    char * strIPAddr=inet_ntoa(*(struct in_addr *)hn->h_addr_list[0]);//把ip换成字符串形式
    this->m_host_ip.SetWindowTextA(strIPAddr);

    this->UpdateData(0);


http://blog.csdn.net/wanglang3081/article/details/7876423

原创粉丝点击