-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathversion.py
More file actions
40 lines (34 loc) · 1.26 KB
/
Copy pathversion.py
File metadata and controls
40 lines (34 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/usr/bin/env python3
import re, sys, urllib.request
URL = "https://mikrotik.com/download/winbox"
UA = "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120 Safari/537.36"
req = urllib.request.Request(
URL, headers={"User-Agent": UA, "Accept-Language": "en-US,en;q=0.9"}
)
html = urllib.request.urlopen(req).read().decode("utf-8", "replace")
betas = [(int(n), f"4.0beta{n}") for n in re.findall(r"\bv4\.0beta(\d+)\b", html)]
if not betas:
print("Failed to detect WinBox v4 beta version from page", file=sys.stderr)
sys.exit(1)
_, ver = max(betas, key=lambda x: x[0])
msha = re.search(
r"WinBox_Linux\.zip.{0,1000}?([0-9a-f]{64})", html, re.IGNORECASE | re.DOTALL
)
if not msha:
print(
"Failed to detect Linux SHA256 for WinBox_Linux.zip from page", file=sys.stderr
)
# Helpful debug: show the area around the filename
idx = html.lower().find("winbox_linux.zip")
if idx != -1:
snippet = html[max(0, idx - 200) : idx + 1200]
print(
"\n--- debug snippet around WinBox_Linux.zip ---\n",
snippet,
"\n--- end ---\n",
file=sys.stderr,
)
sys.exit(1)
sha = msha.group(1).lower()
print(f"WINBOX_VERSION={ver}")
print(f"WINBOX_SHA256={sha}")