c++检测本机网络

bool checkProxyNetwork()
{
WSADATA wsaData;
if (WSAStartup(MAKEWORD(2, 2), &wsaData) != 0)
{
qDebug() << "找不到可使用的WinSock dll!" << endl;
return false;
}
SOCKET sClient = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if (sClient == INVALID_SOCKET)
{
qDebug() << "找不到可使用的WinSock dll!" << endl;
return false;
}
bool isSucc = true;
SOCKADDR_IN addrServ;
addrServ.sin_family = AF_INET;
addrServ.sin_addr.S_un.S_addr = inet_addr("14.215.177.37");
addrServ.sin_port = htons(80);
if (::connect(sClient, (sockaddr *)&addrServ, sizeof(sockaddr)) == SOCKET_ERROR)
{
closesocket(sClient);
isSucc = false;
}
else
qDebug() << "连接服务器成功!" << endl;

closesocket(sClient);
WSACleanup();
return isSucc;
}

posted on 2017-05-04 21:34  阿兴的平凡世界  阅读(781)  评论(0编辑  收藏  举报

导航