Qt通过域名获取ip

//不加上会报错
#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

你可能感兴趣的:(Qt通过域名获取ip)