From ea2ec707015769dcda61b1fca8d1370e0d874976 Mon Sep 17 00:00:00 2001 From: jaydee Date: Fri, 17 Feb 2023 21:18:08 +0100 Subject: [PATCH] added update --- scan_tasmotas.py | 46 +++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 43 insertions(+), 3 deletions(-) diff --git a/scan_tasmotas.py b/scan_tasmotas.py index 50e024f..8a230dd 100644 --- a/scan_tasmotas.py +++ b/scan_tasmotas.py @@ -14,9 +14,9 @@ import ctypes import getopt import requests CHECK_MARK = "\033[0;32m\xE2\x9C\x94\033[0m" -_MQTT_SETUP = _BACKUP = _APPLY = _WIFI_SETUP = False +_MQTT_SETUP = _BACKUP = _APPLY = _WIFI_SETUP = _UPGRADE_FW = False try: - opts, args = getopt.getopt(sys.argv[1:], "wh:bm", ["command=", "help", "output=", "backup"]) + opts, args = getopt.getopt(sys.argv[1:], "wh:bmu", ["command=", "help", "output=", "backup"]) except getopt.GetoptError as err: # print help information and exit: print(str(err)) # will print something like "option -a not recognized" @@ -36,6 +36,8 @@ for o, a in opts: _WIFI_SETUP = True elif o in ("-a", "--apply"): _APPLY = True + elif o in ("-u", "--upgrade_fw"): + _UPGRADE_FW = True else: _WIZZARD = True @@ -90,7 +92,41 @@ def create_backup(): #print(sys_ip + " : Not a listening") pass +def upgrade_fw(): + cmnd = "nmap -sP 192.168.77.*|grep \"Nmap scan report\"|egrep -o \"[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\"" + #print(cmnd) + status, output = subprocess.getstatusoutput(cmnd) + # print(output) + + ips = output.splitlines() + for sys_ip in ips: + print("Thsis is ip : " + sys_ip) + cmnd = "nmap " + sys_ip + " -p80|grep \"80/tcp open http\"" + status, output = subprocess.getstatusoutput(cmnd) + # print("status of 80 : " + str(status)) + if status == 0: + try: + # url = "http://" + sys_ip + "/cm?user=admin&password=l4c1j4yd33Du5l0&cmnd=STATUS+5" + + url = "http://" + sys_ip + "/cm?user=admin&password=l4c1j4yd33Du5l0&cmnd=STATUS+1" + #print(url) + resp = requests.get(url) + json_str = resp.content.decode('utf-8') + #print(json_str) + tasm_data = json.loads(json_str) + #print(tasm_data) + print(tasm_data["StatusPRM"]["OtaUrl"]) + + + except: + #print(sys_ip + " : Not a tasmota!") + pass + else: + #print(sys_ip + " : Not a listening") + pass + + def wifi_setup(): SSID1 = input(">> SID1 ? (default=jaydee) : ") or "jaydee" PASS1 = input(">> PASS1 ? (default=) : ") or "" @@ -169,4 +205,8 @@ if _MQTT_SETUP: mqtt_setup() if _WIFI_SETUP: - wifi_setup() \ No newline at end of file + wifi_setup() + + +if _UPGRADE_FW: + upgrade_fw() \ No newline at end of file