https://github.com/jaytwolab/qping
Ping class for Qt 5 or 6 (without user elevation) :kr: Qt 5 또는 6 기반 계정 상승 필요없는 핑
https://github.com/jaytwolab/qping
cpp languages ping qt qt5 qt6
Last synced: 6 months ago
JSON representation
Ping class for Qt 5 or 6 (without user elevation) :kr: Qt 5 또는 6 기반 계정 상승 필요없는 핑
- Host: GitHub
- URL: https://github.com/jaytwolab/qping
- Owner: JayTwoLab
- License: mit
- Created: 2018-06-02T14:58:26.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2023-03-29T04:50:11.000Z (almost 3 years ago)
- Last Synced: 2025-06-05T04:41:45.150Z (8 months ago)
- Topics: cpp, languages, ping, qt, qt5, qt6
- Language: C++
- Homepage: https://jaytwolab.github.io/QPing/
- Size: 56.6 KB
- Stars: 20
- Watchers: 1
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.ko.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
## QPing
> *Read this in other languages: [English](README.md), :kr: [한국어](README.ko.md)*

- Ping 클래스. Qt 5 또는 6
- 이 클래스로 ping을 쏘고 응답을 확인할 수 있습니다.
### 노트
- ICMP 프로토콜을 사용하는 함수를 호출하지 않도록 구성하였습니다.
- 저는 예전에 로소켓을 사용하는 유사한 클래스를 만든 적이 있습니다.
- 하지만 그런 경우 사용자 계정의 권한 상승이 필요합니다. root, superuser, admin 등
### 설정 방법
- QPing.h, QPing.cpp 를 여러분의 프로젝트에 복사하세요.
- 여러분의 Qt 프로젝트(*.pro)에 해당 소스 코드를 추가하세요.
```qmake
HEADERS += QPing.h
SOURCES += QPing.cpp
```
- 클래스를 활용하는 소스 코드를 넣으세요. main.cpp를 참조하세요.
```cpp
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include "QPing.h"
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
QString destIpAddress = "192.168.200.254";
if ( argc == 2 )
{
// You can use application first parameter
// For example) QPingSF 192.168.0.10
QString strArg = argv[1];
destIpAddress = strArg;
}
// Define your OS and OS language.
// See sample of *.ini for OS. (You can define your own INI file)
// Please suggest strings that can be set in various languages and operating systems.
QString iniFilePath;
QString localSystemName = QLocale::system().name();
/* Returns the language and country of this locale as a string of the form "language_country",
* where language is a lowercase, two-letter ISO 639 language code,
* and country is an uppercase, two- or three-letter ISO 3166 country code.
*/
QString langaugeISO639 = localSystemName.left(2);
#ifdef Q_OS_WIN
if ( langaugeISO639 == "ko" )
{
iniFilePath = ":/ping-config-win-kr.ini"; // Windows, Korean
}
if ( langaugeISO639 == "en" )
{
iniFilePath = ":/ping-config-win-en.ini"; // Windows, English
}
/* TODO:
* Create a new INI file for your native language, referencing an existing INI file.
*/
#endif
#ifdef Q_OS_LINUX
if ( langaugeISO639 == "en" )
{
iniFilePath = ":/ping-config-linux-en.ini"; // Linux, English
}
/* TODO:
* Create a new INI file for your native language, referencing an existing INI file.
*/
#endif
#ifdef Q_OS_MAC
if ( langaugeISO639 == "en" ) // Mac, English
{
// iniFilePath = mac ini... I don't have a Mac, because I'm poor.
}
/* TODO:
* Create a new INI file for your native language, referencing an existing INI file.
*/
#endif
////////////////////
QPing qp; // main class
qp.setIniFile( iniFilePath ); // set configuration file
if ( ! qp.loadIniFile() )
{
std::cout << "[ERROR] Failed to load ini file" << std::endl;
return (-1);
}
// Ping!
QPing::pingResult result = qp.ping(destIpAddress);
switch( result )
{
case QPing::pingSuccess:
std::cout << "[SUCCESS] Success to ping" << std::endl;
break;
case QPing::pingFailed:
std::cout << "[FAILED] Failed to ping" << std::endl;
break;
case QPing::initFailed1: // "success string is empty"
case QPing::initFailed2: // "failed string is empty"
std::cout << "[ERROR] Initialization is failed" << std::endl;
break;
case QPing::notFound: // something wrong
std::cout << "[ERROR] Result is not found" << std::endl;
break;
default:
std::cout << "[ERROR] Undefined result : " << ((quint32)result) << std::endl;
break;
}
return 0;
}
```
### 라이센스
- QPing은 MIT 라이센스입니다. https://github.com/JayTwoLab/QPing
### 문의
- 이슈를 남겨 주세요. https://github.com/JayTwoLab/QPing/issues