Qt 查看IP是否在线的两种方法
linux-dash
A beautiful web dashboard for Linux
项目地址:https://gitcode.com/gh_mirrors/li/linux-dash
免费下载资源
·
1、使用QProcess和Ping
QProcess *cmd = new QProcess;
#ifdef _TTY_ARMV4_
QString strArg = "ping -s 1 -c 1 " + b_tmpIpStr; //linux平台下的格式
#else
QString strArg = "ping " + b_tmpIpStr + " -n 1 -w " + QString::number(m_timeoutInt) ; //windows下的格式
#endif
cmd->start(strArg);
cmd->waitForReadyRead();
cmd->waitForFinished();
QString retStr = cmd->readAll();
if (retStr.indexOf("TTL") != -1)
{
qDebug() << m_curIpStr <<"is online!\n";
}
retStr.clear();
2、使用QTcpSocket连接
QTcpSocket socket(0);
socket.abort(); //取消原有连接
socket.connectToHost(m_curIpStr,m_curPort); //建立一个TCP连接
if(socket.waitForConnected(m_timeoutInt))
{
qDebug()<<m_curIpStr<<"is online\n";
}
socket.close();
GitHub 加速计划 / li / linux-dash
10.39 K
1.2 K
下载
A beautiful web dashboard for Linux
最近提交(Master分支:2 个月前 )
186a802e
added ecosystem file for PM2 4 年前
5def40a3
Add host customization support for the NodeJS version 4 年前
更多推荐
已为社区贡献6条内容
所有评论(0)