ww-net 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- ww_net-0.1.0/LICENSE +21 -0
- ww_net-0.1.0/PKG-INFO +96 -0
- ww_net-0.1.0/README.md +69 -0
- ww_net-0.1.0/pyproject.toml +41 -0
- ww_net-0.1.0/setup.cfg +4 -0
- ww_net-0.1.0/ww_net/__init__.py +31 -0
- ww_net-0.1.0/ww_net/net.py +135 -0
- ww_net-0.1.0/ww_net.egg-info/PKG-INFO +96 -0
- ww_net-0.1.0/ww_net.egg-info/SOURCES.txt +10 -0
- ww_net-0.1.0/ww_net.egg-info/dependency_links.txt +1 -0
- ww_net-0.1.0/ww_net.egg-info/requires.txt +1 -0
- ww_net-0.1.0/ww_net.egg-info/top_level.txt +1 -0
ww_net-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Marcus Aurelius
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
ww_net-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: ww-net
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Een netwerk-checker die geduldig wacht, slim omgaat met DNS, en logt via arin_log.
|
|
5
|
+
Author: Marcus Aurelius
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/marcus-aurelius-hu/ww_net
|
|
8
|
+
Project-URL: Repository, https://github.com/marcus-aurelius-hu/ww_net
|
|
9
|
+
Project-URL: Issues, https://github.com/marcus-aurelius-hu/ww_net/issues
|
|
10
|
+
Keywords: netwerk,network,internet,host,dns,check,pipeline
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
17
|
+
Classifier: Operating System :: Microsoft :: Windows
|
|
18
|
+
Classifier: Operating System :: POSIX :: Linux
|
|
19
|
+
Classifier: Intended Audience :: Developers
|
|
20
|
+
Classifier: Topic :: System :: Networking
|
|
21
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
22
|
+
Requires-Python: >=3.9
|
|
23
|
+
Description-Content-Type: text/markdown
|
|
24
|
+
License-File: LICENSE
|
|
25
|
+
Requires-Dist: arin-log>=0.2.0
|
|
26
|
+
Dynamic: license-file
|
|
27
|
+
|
|
28
|
+
# py_net
|
|
29
|
+
|
|
30
|
+
Een netwerk-checker die geduldig wacht, slim omgaat met DNS, en logt
|
|
31
|
+
via `arin_log`. Gebouwd voor langlopende pipelines die niet mogen vallen
|
|
32
|
+
als het internet even wegvalt.
|
|
33
|
+
|
|
34
|
+
## Waarom py_net?
|
|
35
|
+
|
|
36
|
+
- **Hamert het netwerk niet.** Wacht met oplopende intervallen (1s → 15s),
|
|
37
|
+
niet met een vaste korte poll.
|
|
38
|
+
- **Kiest willekeurig een DNS-server.** Cloudflare, Google, Quad9, OpenDNS —
|
|
39
|
+
als één plat ligt, probeert hij een andere.
|
|
40
|
+
- **Wacht uren als het moet.** Eén parameter (`wait`) in seconden; tot 12 uur
|
|
41
|
+
of langer, zonder het netwerk te belasten.
|
|
42
|
+
- **Logt via `arin_log`.** Netwerkproblemen komen in je bestaande logbestand,
|
|
43
|
+
niet in een apart spoor dat je later moet samenvoegen.
|
|
44
|
+
- **Werkt voor twee vragen.** "Is er internet?" én "Is déze host bereikbaar?"
|
|
45
|
+
|
|
46
|
+
## Installatie
|
|
47
|
+
|
|
48
|
+
pip install ww-net
|
|
49
|
+
|
|
50
|
+
`arin_log` wordt automatisch mee geïnstalleerd als dependency.
|
|
51
|
+
|
|
52
|
+
## Gebruik
|
|
53
|
+
|
|
54
|
+
from ww_net import is_net, is_host
|
|
55
|
+
|
|
56
|
+
# Controleer of er internet is (wacht tot 12 uur)
|
|
57
|
+
if is_net(wait=43200):
|
|
58
|
+
print("Internet is beschikbaar")
|
|
59
|
+
|
|
60
|
+
# Controleer of een specifieke host bereikbaar is
|
|
61
|
+
if is_host("https://www.google.com/", wait=43200):
|
|
62
|
+
print("Host is bereikbaar")
|
|
63
|
+
|
|
64
|
+
## Wachten
|
|
65
|
+
|
|
66
|
+
De `wait`-parameter is de tijd (in seconden) waarna `py_net` opgeeft.
|
|
67
|
+
De standaardwaarde is `3600` (1 uur). Omdat het in seconden gaat, kun je
|
|
68
|
+
gemakkelijk langere periodes instellen:
|
|
69
|
+
|
|
70
|
+
| Duur | Seconden |
|
|
71
|
+
|------|----------|
|
|
72
|
+
| 1 uur | 3600 |
|
|
73
|
+
| 4 uur | 14400 |
|
|
74
|
+
| 8 uur | 28800 |
|
|
75
|
+
| 12 uur | 43200 |
|
|
76
|
+
|
|
77
|
+
Tijdens het wachten loopt het interval op van 1 seconde tot 15 seconden.
|
|
78
|
+
Zo wordt het netwerk niet onnodig belast, maar blijft `py_net` wel alert.
|
|
79
|
+
|
|
80
|
+
## API
|
|
81
|
+
|
|
82
|
+
| Functie | Beschrijving |
|
|
83
|
+
|---------|--------------|
|
|
84
|
+
| `is_net(wait=None, logloc=None)` | Controleert of er internet is. Wacht tot `wait` seconden. |
|
|
85
|
+
| `is_host(host, wait=None, logloc=None)` | Controleert of `host` bereikbaar is. Wacht tot `wait` seconden. |
|
|
86
|
+
|
|
87
|
+
Beide functies retourneren `True` of `False`.
|
|
88
|
+
|
|
89
|
+
## Logging
|
|
90
|
+
|
|
91
|
+
`py_net` logt via `arin_log`. De `logloc`-parameter wordt doorgegeven aan
|
|
92
|
+
`arin_log`, zodat je de logberichten in het juiste logbestand kunt plaatsen.
|
|
93
|
+
|
|
94
|
+
## Licentie
|
|
95
|
+
|
|
96
|
+
MIT — zie [LICENSE](LICENSE).
|
ww_net-0.1.0/README.md
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
# py_net
|
|
2
|
+
|
|
3
|
+
Een netwerk-checker die geduldig wacht, slim omgaat met DNS, en logt
|
|
4
|
+
via `arin_log`. Gebouwd voor langlopende pipelines die niet mogen vallen
|
|
5
|
+
als het internet even wegvalt.
|
|
6
|
+
|
|
7
|
+
## Waarom py_net?
|
|
8
|
+
|
|
9
|
+
- **Hamert het netwerk niet.** Wacht met oplopende intervallen (1s → 15s),
|
|
10
|
+
niet met een vaste korte poll.
|
|
11
|
+
- **Kiest willekeurig een DNS-server.** Cloudflare, Google, Quad9, OpenDNS —
|
|
12
|
+
als één plat ligt, probeert hij een andere.
|
|
13
|
+
- **Wacht uren als het moet.** Eén parameter (`wait`) in seconden; tot 12 uur
|
|
14
|
+
of langer, zonder het netwerk te belasten.
|
|
15
|
+
- **Logt via `arin_log`.** Netwerkproblemen komen in je bestaande logbestand,
|
|
16
|
+
niet in een apart spoor dat je later moet samenvoegen.
|
|
17
|
+
- **Werkt voor twee vragen.** "Is er internet?" én "Is déze host bereikbaar?"
|
|
18
|
+
|
|
19
|
+
## Installatie
|
|
20
|
+
|
|
21
|
+
pip install ww-net
|
|
22
|
+
|
|
23
|
+
`arin_log` wordt automatisch mee geïnstalleerd als dependency.
|
|
24
|
+
|
|
25
|
+
## Gebruik
|
|
26
|
+
|
|
27
|
+
from ww_net import is_net, is_host
|
|
28
|
+
|
|
29
|
+
# Controleer of er internet is (wacht tot 12 uur)
|
|
30
|
+
if is_net(wait=43200):
|
|
31
|
+
print("Internet is beschikbaar")
|
|
32
|
+
|
|
33
|
+
# Controleer of een specifieke host bereikbaar is
|
|
34
|
+
if is_host("https://www.google.com/", wait=43200):
|
|
35
|
+
print("Host is bereikbaar")
|
|
36
|
+
|
|
37
|
+
## Wachten
|
|
38
|
+
|
|
39
|
+
De `wait`-parameter is de tijd (in seconden) waarna `py_net` opgeeft.
|
|
40
|
+
De standaardwaarde is `3600` (1 uur). Omdat het in seconden gaat, kun je
|
|
41
|
+
gemakkelijk langere periodes instellen:
|
|
42
|
+
|
|
43
|
+
| Duur | Seconden |
|
|
44
|
+
|------|----------|
|
|
45
|
+
| 1 uur | 3600 |
|
|
46
|
+
| 4 uur | 14400 |
|
|
47
|
+
| 8 uur | 28800 |
|
|
48
|
+
| 12 uur | 43200 |
|
|
49
|
+
|
|
50
|
+
Tijdens het wachten loopt het interval op van 1 seconde tot 15 seconden.
|
|
51
|
+
Zo wordt het netwerk niet onnodig belast, maar blijft `py_net` wel alert.
|
|
52
|
+
|
|
53
|
+
## API
|
|
54
|
+
|
|
55
|
+
| Functie | Beschrijving |
|
|
56
|
+
|---------|--------------|
|
|
57
|
+
| `is_net(wait=None, logloc=None)` | Controleert of er internet is. Wacht tot `wait` seconden. |
|
|
58
|
+
| `is_host(host, wait=None, logloc=None)` | Controleert of `host` bereikbaar is. Wacht tot `wait` seconden. |
|
|
59
|
+
|
|
60
|
+
Beide functies retourneren `True` of `False`.
|
|
61
|
+
|
|
62
|
+
## Logging
|
|
63
|
+
|
|
64
|
+
`py_net` logt via `arin_log`. De `logloc`-parameter wordt doorgegeven aan
|
|
65
|
+
`arin_log`, zodat je de logberichten in het juiste logbestand kunt plaatsen.
|
|
66
|
+
|
|
67
|
+
## Licentie
|
|
68
|
+
|
|
69
|
+
MIT — zie [LICENSE](LICENSE).
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=77.0.0", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "ww-net"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Een netwerk-checker die geduldig wacht, slim omgaat met DNS, en logt via arin_log."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.9"
|
|
11
|
+
license = "MIT"
|
|
12
|
+
license-files = ["LICENSE"]
|
|
13
|
+
authors = [
|
|
14
|
+
{ name = "Marcus Aurelius" }
|
|
15
|
+
]
|
|
16
|
+
keywords = ["netwerk", "network", "internet", "host", "dns", "check", "pipeline"]
|
|
17
|
+
classifiers = [
|
|
18
|
+
"Programming Language :: Python :: 3",
|
|
19
|
+
"Programming Language :: Python :: 3.9",
|
|
20
|
+
"Programming Language :: Python :: 3.10",
|
|
21
|
+
"Programming Language :: Python :: 3.11",
|
|
22
|
+
"Programming Language :: Python :: 3.12",
|
|
23
|
+
"Programming Language :: Python :: 3.13",
|
|
24
|
+
"Operating System :: Microsoft :: Windows",
|
|
25
|
+
"Operating System :: POSIX :: Linux",
|
|
26
|
+
"Intended Audience :: Developers",
|
|
27
|
+
"Topic :: System :: Networking",
|
|
28
|
+
"Topic :: Software Development :: Libraries :: Python Modules",
|
|
29
|
+
]
|
|
30
|
+
|
|
31
|
+
dependencies = [
|
|
32
|
+
"arin-log>=0.2.0",
|
|
33
|
+
]
|
|
34
|
+
|
|
35
|
+
[project.urls]
|
|
36
|
+
Homepage = "https://github.com/marcus-aurelius-hu/ww_net"
|
|
37
|
+
Repository = "https://github.com/marcus-aurelius-hu/ww_net"
|
|
38
|
+
Issues = "https://github.com/marcus-aurelius-hu/ww_net/issues"
|
|
39
|
+
|
|
40
|
+
[tool.setuptools]
|
|
41
|
+
packages = ["ww_net"]
|
ww_net-0.1.0/setup.cfg
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"""
|
|
2
|
+
ww_net
|
|
3
|
+
------
|
|
4
|
+
Een lichtgewicht netwerk-checker voor langlopende pipelines.
|
|
5
|
+
|
|
6
|
+
Controleert of er internet is en of een specifieke host bereikbaar is.
|
|
7
|
+
Wacht geduldig tot de verbinding terugkomt, met oplopende intervallen,
|
|
8
|
+
en logt ondertussen via arin_log.
|
|
9
|
+
|
|
10
|
+
Publieke API
|
|
11
|
+
------------
|
|
12
|
+
is_net(wait=None, logloc=None)
|
|
13
|
+
Controleert of er internet is.
|
|
14
|
+
|
|
15
|
+
is_host(host, wait=None, logloc=None)
|
|
16
|
+
Controleert of een specifieke host bereikbaar is.
|
|
17
|
+
|
|
18
|
+
Beide functies retourneren True of False.
|
|
19
|
+
"""
|
|
20
|
+
|
|
21
|
+
__version__ = "0.1.0"
|
|
22
|
+
|
|
23
|
+
from ww_net.net import (
|
|
24
|
+
is_net,
|
|
25
|
+
is_host,
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
__all__ = [
|
|
29
|
+
"is_net",
|
|
30
|
+
"is_host",
|
|
31
|
+
]
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
from socket import gaierror, gethostbyname, socket, AF_INET, SOCK_STREAM
|
|
2
|
+
from time import sleep, time, strftime
|
|
3
|
+
from urllib.parse import urlparse
|
|
4
|
+
from arin_log import log_notes
|
|
5
|
+
from random import choice
|
|
6
|
+
from sys import _getframe
|
|
7
|
+
from os import path
|
|
8
|
+
|
|
9
|
+
br = chr(10)
|
|
10
|
+
prgnm = path.basename(__file__).split('.')[0]
|
|
11
|
+
|
|
12
|
+
class CheckNet:
|
|
13
|
+
def __init__(self, timeout=1.5, wait=3600, logloc=None):
|
|
14
|
+
self.timeout = timeout
|
|
15
|
+
self.wait = wait
|
|
16
|
+
self.dns_servers = ["1.1.1.1", "8.8.8.8", "9.9.9.9", "208.67.222.222"]
|
|
17
|
+
self.logloc = prgnm if logloc is None else logloc
|
|
18
|
+
self.slpd = {'1;5': 1, '6;10': 2, '11;20': 3, '21;50': 4, '51;100': 5, '101;150': 6, '151;200': 7,
|
|
19
|
+
'201;300': 8, '301;400': 9, '401;600': 10, '601;1000': 11, '1001;1500': 12,
|
|
20
|
+
'1501;999999999': 15}
|
|
21
|
+
|
|
22
|
+
def get_interval(self, count):
|
|
23
|
+
"""Return the sleep time based on the poll_count without logging."""
|
|
24
|
+
slpt = 1
|
|
25
|
+
for key in self.slpd:
|
|
26
|
+
start, end = map(int, key.split(';'))
|
|
27
|
+
if start <= count <= end:
|
|
28
|
+
slpt = self.slpd[key]
|
|
29
|
+
break
|
|
30
|
+
return slpt
|
|
31
|
+
|
|
32
|
+
def tcp_check(self, ip=None, timeout=None):
|
|
33
|
+
if timeout is None:
|
|
34
|
+
timeout = self.timeout if ip is None else 2.0
|
|
35
|
+
host = choice(self.dns_servers) if ip is None else ip
|
|
36
|
+
ports = [443, 80]
|
|
37
|
+
|
|
38
|
+
for port in ports:
|
|
39
|
+
try:
|
|
40
|
+
with socket(AF_INET, SOCK_STREAM) as sock:
|
|
41
|
+
sock.settimeout(timeout)
|
|
42
|
+
if sock.connect_ex((host, port)) == 0:
|
|
43
|
+
return True
|
|
44
|
+
except Exception:
|
|
45
|
+
continue
|
|
46
|
+
return False
|
|
47
|
+
|
|
48
|
+
def is_net(self, wait=None, logloc=None):
|
|
49
|
+
wait = self.wait if wait is None else wait
|
|
50
|
+
logloc = self.logloc if logloc is None else logloc
|
|
51
|
+
if self.tcp_check():
|
|
52
|
+
return True
|
|
53
|
+
return self.wait_net(typ='internet', wait=wait, logloc=logloc)
|
|
54
|
+
|
|
55
|
+
def wait_net(self, typ=None, wait=None, logloc=None):
|
|
56
|
+
typ = 'internet' if typ is None else typ
|
|
57
|
+
wait = self.wait if wait is None else wait
|
|
58
|
+
logloc = self.logloc if logloc is None else logloc
|
|
59
|
+
fcnm = _getframe().f_code.co_name
|
|
60
|
+
|
|
61
|
+
log_notes(f"⚠️ {typ} ; connection ; exception", logloc=logloc)
|
|
62
|
+
log_notes(f"⚠️ {prgnm} ; {fcnm} ; {strftime('%H:%M:%S')}", cons=False, logloc=logloc)
|
|
63
|
+
exc_time = time()
|
|
64
|
+
start_time = time()
|
|
65
|
+
count = 1
|
|
66
|
+
|
|
67
|
+
while time() - start_time < wait:
|
|
68
|
+
if self.tcp_check():
|
|
69
|
+
log_notes(f"✅ {typ} ; connection ; restored", logloc=logloc)
|
|
70
|
+
log_notes(f"✅ {prgnm} ; {fcnm} ; {time() - exc_time:.3f} sec{br}", cons=False, logloc=logloc)
|
|
71
|
+
return True
|
|
72
|
+
interval = self.get_interval(count)
|
|
73
|
+
count += 1
|
|
74
|
+
sleep(interval)
|
|
75
|
+
log_notes(f"⚠️ {typ} ; connection ; timeout", logloc=logloc)
|
|
76
|
+
log_notes(f"⚠️ {prgnm} ; {fcnm} ; {time() - exc_time:.3f} sec{br}", cons=False, logloc=logloc)
|
|
77
|
+
return False
|
|
78
|
+
|
|
79
|
+
def is_host(self, host, wait=None, logloc=None):
|
|
80
|
+
wait = self.wait if wait is None else wait
|
|
81
|
+
logloc = self.logloc if logloc is None else logloc
|
|
82
|
+
fcnm = _getframe().f_code.co_name
|
|
83
|
+
|
|
84
|
+
if "://" in host:
|
|
85
|
+
host = urlparse(host).netloc.replace('www.', '')
|
|
86
|
+
|
|
87
|
+
if self.tcp_check():
|
|
88
|
+
try:
|
|
89
|
+
gethostbyname(host)
|
|
90
|
+
start_time = time()
|
|
91
|
+
exc_time = None
|
|
92
|
+
count = 1
|
|
93
|
+
while time() - start_time < wait:
|
|
94
|
+
if count == 2:
|
|
95
|
+
log_notes(f"⚠️ {host} ; connection ; exception", logloc=logloc)
|
|
96
|
+
log_notes(f"⚠️ {prgnm} ; {fcnm} ; {strftime('%H:%M:%S')}", cons=False, logloc=logloc)
|
|
97
|
+
exc_time = time()
|
|
98
|
+
if self.tcp_check(ip=host):
|
|
99
|
+
if count > 1:
|
|
100
|
+
log_notes(f"✅ {host} ; connection ; restored", logloc=logloc)
|
|
101
|
+
log_notes(f"✅ {prgnm} ; {fcnm} ; {time() - exc_time:.3f} sec{br}", cons=False,
|
|
102
|
+
logloc=logloc)
|
|
103
|
+
return True
|
|
104
|
+
interval = self.get_interval(count)
|
|
105
|
+
count += 1
|
|
106
|
+
sleep(interval)
|
|
107
|
+
log_notes(f"⚠️ {host} ; connection ; timeout", logloc=logloc)
|
|
108
|
+
log_notes(f"⚠️ {prgnm} ; {fcnm} ; {time() - exc_time:.3f} sec{br}", cons=False, logloc=logloc)
|
|
109
|
+
return False
|
|
110
|
+
except gaierror:
|
|
111
|
+
return self.wait_net(typ=host, wait=wait, logloc=logloc)
|
|
112
|
+
except Exception:
|
|
113
|
+
return self.wait_net(typ=host, wait=wait, logloc=logloc)
|
|
114
|
+
else:
|
|
115
|
+
return self.wait_net(typ=host, wait=wait, logloc=logloc)
|
|
116
|
+
|
|
117
|
+
_net = CheckNet()
|
|
118
|
+
|
|
119
|
+
def is_net(wait=None, logloc=None):
|
|
120
|
+
return _net.is_net(wait=wait, logloc=logloc)
|
|
121
|
+
|
|
122
|
+
def is_host(host, wait=None, logloc=None):
|
|
123
|
+
return _net.is_host(host, wait=wait, logloc=logloc)
|
|
124
|
+
|
|
125
|
+
__all__ = ['is_net', 'is_host']
|
|
126
|
+
|
|
127
|
+
if __name__ == "__main__":
|
|
128
|
+
t0 = time()
|
|
129
|
+
result = is_net(wait=360)
|
|
130
|
+
print(f"🌐 internet ; {result} ; {(time() - t0) * 1000:.2f} msec")
|
|
131
|
+
|
|
132
|
+
t0 = time()
|
|
133
|
+
result = is_host('https://nl.investing.com/', wait=360)
|
|
134
|
+
print(f"🌍 nl.investing.com ; {result} ; {(time() - t0) * 1000:.2f} msec")
|
|
135
|
+
exit(0)
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: ww-net
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Een netwerk-checker die geduldig wacht, slim omgaat met DNS, en logt via arin_log.
|
|
5
|
+
Author: Marcus Aurelius
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/marcus-aurelius-hu/ww_net
|
|
8
|
+
Project-URL: Repository, https://github.com/marcus-aurelius-hu/ww_net
|
|
9
|
+
Project-URL: Issues, https://github.com/marcus-aurelius-hu/ww_net/issues
|
|
10
|
+
Keywords: netwerk,network,internet,host,dns,check,pipeline
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
17
|
+
Classifier: Operating System :: Microsoft :: Windows
|
|
18
|
+
Classifier: Operating System :: POSIX :: Linux
|
|
19
|
+
Classifier: Intended Audience :: Developers
|
|
20
|
+
Classifier: Topic :: System :: Networking
|
|
21
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
22
|
+
Requires-Python: >=3.9
|
|
23
|
+
Description-Content-Type: text/markdown
|
|
24
|
+
License-File: LICENSE
|
|
25
|
+
Requires-Dist: arin-log>=0.2.0
|
|
26
|
+
Dynamic: license-file
|
|
27
|
+
|
|
28
|
+
# py_net
|
|
29
|
+
|
|
30
|
+
Een netwerk-checker die geduldig wacht, slim omgaat met DNS, en logt
|
|
31
|
+
via `arin_log`. Gebouwd voor langlopende pipelines die niet mogen vallen
|
|
32
|
+
als het internet even wegvalt.
|
|
33
|
+
|
|
34
|
+
## Waarom py_net?
|
|
35
|
+
|
|
36
|
+
- **Hamert het netwerk niet.** Wacht met oplopende intervallen (1s → 15s),
|
|
37
|
+
niet met een vaste korte poll.
|
|
38
|
+
- **Kiest willekeurig een DNS-server.** Cloudflare, Google, Quad9, OpenDNS —
|
|
39
|
+
als één plat ligt, probeert hij een andere.
|
|
40
|
+
- **Wacht uren als het moet.** Eén parameter (`wait`) in seconden; tot 12 uur
|
|
41
|
+
of langer, zonder het netwerk te belasten.
|
|
42
|
+
- **Logt via `arin_log`.** Netwerkproblemen komen in je bestaande logbestand,
|
|
43
|
+
niet in een apart spoor dat je later moet samenvoegen.
|
|
44
|
+
- **Werkt voor twee vragen.** "Is er internet?" én "Is déze host bereikbaar?"
|
|
45
|
+
|
|
46
|
+
## Installatie
|
|
47
|
+
|
|
48
|
+
pip install ww-net
|
|
49
|
+
|
|
50
|
+
`arin_log` wordt automatisch mee geïnstalleerd als dependency.
|
|
51
|
+
|
|
52
|
+
## Gebruik
|
|
53
|
+
|
|
54
|
+
from ww_net import is_net, is_host
|
|
55
|
+
|
|
56
|
+
# Controleer of er internet is (wacht tot 12 uur)
|
|
57
|
+
if is_net(wait=43200):
|
|
58
|
+
print("Internet is beschikbaar")
|
|
59
|
+
|
|
60
|
+
# Controleer of een specifieke host bereikbaar is
|
|
61
|
+
if is_host("https://www.google.com/", wait=43200):
|
|
62
|
+
print("Host is bereikbaar")
|
|
63
|
+
|
|
64
|
+
## Wachten
|
|
65
|
+
|
|
66
|
+
De `wait`-parameter is de tijd (in seconden) waarna `py_net` opgeeft.
|
|
67
|
+
De standaardwaarde is `3600` (1 uur). Omdat het in seconden gaat, kun je
|
|
68
|
+
gemakkelijk langere periodes instellen:
|
|
69
|
+
|
|
70
|
+
| Duur | Seconden |
|
|
71
|
+
|------|----------|
|
|
72
|
+
| 1 uur | 3600 |
|
|
73
|
+
| 4 uur | 14400 |
|
|
74
|
+
| 8 uur | 28800 |
|
|
75
|
+
| 12 uur | 43200 |
|
|
76
|
+
|
|
77
|
+
Tijdens het wachten loopt het interval op van 1 seconde tot 15 seconden.
|
|
78
|
+
Zo wordt het netwerk niet onnodig belast, maar blijft `py_net` wel alert.
|
|
79
|
+
|
|
80
|
+
## API
|
|
81
|
+
|
|
82
|
+
| Functie | Beschrijving |
|
|
83
|
+
|---------|--------------|
|
|
84
|
+
| `is_net(wait=None, logloc=None)` | Controleert of er internet is. Wacht tot `wait` seconden. |
|
|
85
|
+
| `is_host(host, wait=None, logloc=None)` | Controleert of `host` bereikbaar is. Wacht tot `wait` seconden. |
|
|
86
|
+
|
|
87
|
+
Beide functies retourneren `True` of `False`.
|
|
88
|
+
|
|
89
|
+
## Logging
|
|
90
|
+
|
|
91
|
+
`py_net` logt via `arin_log`. De `logloc`-parameter wordt doorgegeven aan
|
|
92
|
+
`arin_log`, zodat je de logberichten in het juiste logbestand kunt plaatsen.
|
|
93
|
+
|
|
94
|
+
## Licentie
|
|
95
|
+
|
|
96
|
+
MIT — zie [LICENSE](LICENSE).
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
arin-log>=0.2.0
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
ww_net
|