From f0bdc0af755f9209a851a82515f25306eebae3b5 Mon Sep 17 00:00:00 2001 From: Markus Birth Date: Tue, 23 Jan 2018 22:59:21 +0100 Subject: [PATCH] Scanner for unknown models. --- tclcheck_findprd2.py | 66 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 tclcheck_findprd2.py diff --git a/tclcheck_findprd2.py b/tclcheck_findprd2.py new file mode 100644 index 0000000..8e5ee44 --- /dev/null +++ b/tclcheck_findprd2.py @@ -0,0 +1,66 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- + +# pylint: disable=C0111,C0326,C0103 + +import collections +import sys +import tcllib +from requests.exceptions import RequestException, Timeout + +# Variants to scan for +SCAN_VARIANTS = ["001", "003", "009", "010", "700"] + +tcllib.make_escapes_work() + +fc = tcllib.FotaCheck() +fc.serid = "3531510" +fc.fv = "AAA000" +fc.mode = fc.MODE.FULL + +# CLTP = 10 (only show actual updates or HTTP 206) / 2010 (always show latest version for MODE.FULL) +#fc.cltp = fc.CLTP.MOBILE +fc.cltp = fc.CLTP.DESKTOP + +dp = tcllib.DefaultParser(__file__) +dp.add_argument("floor", nargs="?", help="Model number to start with", type=int, default=63116) +dp.add_argument("ceiling", nargs="?", help="Model number to end with", type=int, default=99999) +args = dp.parse_args(sys.argv[1:]) + +floor = args.floor +ceiling = args.ceiling + 1 +if ceiling < floor: + print("Invalid range!") + raise SystemExit + +print("Loading list of known devices...", end="", flush=True) +prd_db = tcllib.FotaCheck.get_devicelist() +print(" OK") + +print("Valid PRDs not already in database:") + +known_centers = set(int(x.replace("PRD-", "").split("-")[0]) for x in prd_db) +scan_list = set(range(floor, ceiling)) + +to_scan = scan_list - known_centers +total_count = len(to_scan) * len(SCAN_VARIANTS) +done_count = 0 + +for center in to_scan: + for j in SCAN_VARIANTS: + curef = "PRD-{:05}-{:3}".format(center, j) + done_count += 1 + print("Checking {} ({}/{})".format(curef, done_count, total_count)) + print(tcllib.ANSI_UP_DEL, end="") + try: + fc.reset_session() + fc.curef = curef + check_xml = fc.do_check(https=False, max_tries=20) + curef, fv, tv, fw_id, fileid, fn, fsize, fhash = fc.parse_check(check_xml) + txt_tv = tv + print("{}: {} {}".format(curef, txt_tv, fhash)) + except (SystemExit, RequestException, Timeout) as e: + continue + +print("Scan complete.") +tcllib.FotaCheck.write_info_if_dumps_found()