An open API service indexing awesome lists of open source software.

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 기반 계정 상승 필요없는 핑

Awesome Lists containing this project

README

          

## QPing

> *Read this in other languages: [English](README.md), :kr: [한국어](README.ko.md)*

![](markdown-data/qping.png)

- 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