您的位置:首页 > 编程语言 > Qt开发

Qt通过域名获取ip

2017-11-23 15:25 309 查看
//不加上会报错
#pragma comment(lib,"ws2_32.lib")
#pragma comment(lib,"ws2_32.lib")
#include "WinSock.h"
#include "inaddr.h"
QString tcpClientIp ="www.baidu.com";

QString strIp;
QByteArray url = tcpClientIp.toLatin1();
struct hostent *ipH = gethostbyname(url);
if (ipH != NULL)
{
struct in_addr *in = (in_addr *)iPh->h_addr;
char *ch = inet_ntoa(*in);
strIp = QString(QLatin1String(ch));


转至:http://www.lxway.com/414250126.htm
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: