#!/usr/bin/env python3 """ Tasmota Device Discovery Scans network for Tasmota devices by: 1. HTTP-based detection (port 80) 2. Checking for Tasmota JSON API response 3. Looking for Tasmota user-agent in responses """ import socket import subprocess import concurrent.futures from urllib.request import urlopen, Request from urllib.error import URLError, HTTPError import json import time # Network configuration SUBNET = "192.168.1.0/24" TIMEOUT = 2 # seconds def get_local_ip(): """Get local IP to determine subnet""" try: s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) s.connect(("8.8.8.8", 80)) ip = s.getsockname()[0] s.close() return ip except: return "192.168.1.148" def get_subnet_ips(): """Generate list of IPs in subnet""" local_ip = get_local_ip() parts = local_ip.split('.') base = f"{parts[0]}.{parts[1]}.{parts[2]}" return [f"{base}.{i}" for i in range(1, 255)] def check_http(ip): """Check if IP has HTTP service that might be Tasmota""" try: # Try basic HTTP request first req = Request(f"http://{ip}/", headers={'User-Agent': 'Tasmota-Scanner'}) start = time.time() with urlopen(req, timeout=TIMEOUT) as response: elapsed = time.time() - start data = response.read(5000).decode('utf-8', errors='ignore') headers = dict(response.headers) # Check for Tasmota indicators is_tasmota = False evidence = [] # Check for Tasmota-specific headers/content if 'tasmota' in headers.get('Server', '').lower(): is_tasmota = True evidence.append(f"Server header: {headers.get('Server')}") # Check content for Tasmota patterns if 'tasmota' in data.lower(): is_tasmota = True evidence.append("Tasmota keyword in content") # Check for known Tasmota page titles/elements if 'Status' in data and 'tasmota' in data.lower(): is_tasmota = True evidence.append("Tasmota status page detected") # Try Tasmota JSON API try: req_api = Request(f"http://{ip}/cm?cmnd=status%200") with urlopen(req_api, timeout=1) as api_response: api_data = api_response.read(1000).decode('utf-8', errors='ignore') if 'tasmota' in api_data.lower() or 'StatusSNS' in api_data or 'StatusNET' in api_data: is_tasmota = True evidence.append("Tasmota JSON API response") except: pass if is_tasmota: try: title = data.split('