Created
December 8, 2020 02:20
-
-
Save l2m2/d87e7f7e408523cbf1d1cf430786cf8c to your computer and use it in GitHub Desktop.
Qt测试IP是否可达
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <QCoreApplication> | |
#include <QtCore> | |
bool ping_test(const QString &ip) { | |
QStringList parameters; | |
#ifdef Q_OS_WIN | |
parameters << "-n" << "1"; | |
#else | |
parameters << "-c 1"; | |
#endif | |
parameters << ip; | |
int exitCode = QProcess::execute("ping", parameters); | |
return (exitCode == 0); | |
} | |
int main(int argc, char *argv[]) | |
{ | |
QCoreApplication a(argc, argv); | |
qDebug() << ping_test("10.21.2.65"); | |
qDebug() << ping_test("12.45.33.33"); | |
qDebug() << "Done!"; | |
return a.exec(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment