Skip to content

Commit

Permalink
Updated RegEx to handle ping output in russian (#13), updated README
Browse files Browse the repository at this point in the history
  • Loading branch information
retifrav committed Nov 28, 2021
1 parent a04eab1 commit 32d0e45
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
17 changes: 15 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ Network connection quality analyzer.
<!-- MarkdownTOC -->

- [How it works](#how-it-works)
- [ping/ICMP](#pingicmp)
- [HTTP HEAD](#http-head)
- [Platforms support](#platforms-support)
- [3rd-party](#3rd-party)
- [FAQ](#faq)
Expand All @@ -27,8 +29,19 @@ In the end it also does some analytics on the collected data.

There are two modes of pinging the host:

- via system `ping` utility and ICMP requests. Most precise and reliable;
- via HTTP HEAD requests. Not as good, but might be the only option on systems without `ping`.
- via system `ping` utility and ICMP requests;
- via HTTP HEAD requests.

### ping/ICMP

Runs system `ping` utility and parses the output. Has two obvious disadvantages:

- not every system might allow applications to launch CLI tools such as `ping` (*or `ping` might not be even available in the system*);
- parsing the `ping` output is not reliable (*different format on different platforms, multi-language*).

### HTTP HEAD

Simple HTTP HEAD requests. Far less reliable/precise than [ping](#pingicmp) in estimating latency values. At the same time, there is no need to rely on external CLI tool (*and parse its output in different languages*), and sending HTTP requests will work on any platform.

## Platforms support

Expand Down
12 changes: 8 additions & 4 deletions src/functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,18 @@ QStringList getArgs4ping();

// Time (delay/latency) is reported differently on differen OSes:
//
// - Windows: Reply from 87.250.250.242: bytes=32 time=27ms TTL=245
// - Linux: 64 bytes from ya.ru (87.250.250.242): icmp_seq=1 ttl=128 time=30.4 ms
// - Mac OS: 64 bytes from 87.250.250.242: icmp_seq=0 ttl=245 time=37.710 ms
// - Windows:
// + EN: Reply from 87.250.250.242: bytes=32 time=27ms TTL=245
// + RU: Ответ от 87.250.250.242: число байт=32 время=58мс TTL=54
// - GNU/Linux:
// + EN: 64 bytes from ya.ru (87.250.250.242): icmp_seq=1 ttl=128 time=30.4 ms
// - Mac OS:
// + EN: 64 bytes from 87.250.250.242: icmp_seq=0 ttl=245 time=37.710 ms
//
// So we need to use RegEx to get numerical value. It wil be int,
// because fractions of milliseconds are of no interest
#if defined(Q_OS_WIN)
const QRegularExpression timeRegEx = QRegularExpression("(?:time(?:=|<))(\\d+)(\\w+)");
const QRegularExpression timeRegEx = QRegularExpression("(?:(time|время)(?:=|<))(\\d+)(\\w+)");
const QRegularExpression errorRegEx = QRegularExpression("(?:bytes of data:\r\n)(.*)\\.\r\n");
#else
const QRegularExpression timeRegEx = QRegularExpression("(?:time=)(\\d+).* (\\w+)");
Expand Down

0 comments on commit 32d0e45

Please sign in to comment.