Skip to content

Instantly share code, notes, and snippets.

@Commandcracker
Created June 6, 2025 17:47
Show Gist options
  • Save Commandcracker/3c11b62565f849815ea0d9a869c58c20 to your computer and use it in GitHub Desktop.
Save Commandcracker/3c11b62565f849815ea0d9a869c58c20 to your computer and use it in GitHub Desktop.
Small python script to scan for daikin air conditioners
import socket
import ipaddress
import urllib.parse
import psutil
from concurrent.futures import ThreadPoolExecutor, as_completed
import requests
PORT = 80
TIMEOUT = 1 # seconds
def get_local_subnet():
interfaces = psutil.net_if_addrs()
for interface_addrs in interfaces.values():
for addr in interface_addrs:
if addr.family.name == 'AF_INET' and not addr.address.startswith("127."):
ip = addr.address
netmask = addr.netmask
if ip and netmask:
network = ipaddress.IPv4Network(f"{ip}/{netmask}", strict=False)
return str(network)
return None
def is_port_open(ip):
try:
with socket.create_connection((str(ip), PORT), timeout=TIMEOUT):
return str(ip)
except:
return None
def scan_network(network):
open_hosts = []
with ThreadPoolExecutor(max_workers=100) as executor:
futures = {executor.submit(is_port_open, ip): ip for ip in ipaddress.IPv4Network(network)}
for future in as_completed(futures):
result = future.result()
if result:
open_hosts.append(result)
return open_hosts
if __name__ == '__main__':
subnet = get_local_subnet()
if not subnet:
print("Could not determine local subnet.")
else:
print(f"Scanning network {subnet} for devices with port {PORT} open...")
hosts = scan_network(subnet)
print("Devices with port 80 open:")
for host in hosts:
base = "http://"+host
try:
r = requests.get(base + "/common/basic_info")
if r.status_code == 200:
parsed_dict = {
key: urllib.parse.unquote(value) for key, value in
(item.split('=', 1) for item in r.text.split(','))
}
print(parsed_dict.get("pow"), parsed_dict.get("name"), base)
except requests.RequestException:
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment