#!/usr/bin/env python3
import subprocess,re,concurrent.futures
ips='193.134.75.14 193.134.75.15 193.134.75.119 193.134.75.124 193.134.75.128 193.134.75.129 193.134.75.131 193.134.75.132 193.134.75.133 193.134.75.134 193.134.75.150 193.134.75.151 193.134.75.16 193.134.75.160 193.134.75.161 193.134.75.162 193.134.75.163 193.134.75.18 193.134.75.58 193.134.75.71 193.134.75.72 193.134.75.74 193.134.75.75 193.134.75.77 193.134.75.78 193.134.75.83 193.134.75.84 193.134.75.85 193.134.75.86 193.134.74.102'.split()
def one(ip):
 cmd=['curl','--toadex-no-capture','-sk','--http1.1','--path-as-is','--connect-timeout','2','--max-time','5','--resolve',f'va.baloise.de:443:{ip}','-H','X-Bug-Bounty: dwbzn','-i','https://va.baloise.de/SASBIWS/services/Version?wsdl']
 try:r=subprocess.run(cmd,capture_output=True,timeout=7)
 except subprocess.TimeoutExpired:return ip,'TIMEOUT',0,'','',''
 raw=r.stdout
 # last HTTP header in case 100/CONNECT etc
 matches=list(re.finditer(br'HTTP/\S+\s+(\d+)[^\r\n]*\r?\n',raw))
 if not matches:return ip,'ERR',len(raw),'','',raw[:80].decode('latin1','replace').replace('\n',' ')
 m=matches[-1]; start=m.start(); sep=raw.find(b'\r\n\r\n',start)
 sep_len=4
 if sep<0: sep=raw.find(b'\n\n',start);sep_len=2
 headers=raw[start:sep if sep>=0 else len(raw)].decode('latin1','replace')
 body=raw[sep+sep_len:] if sep>=0 else b''
 st=m.group(1).decode()
 loc='';srv=''
 for line in headers.splitlines():
  if line.lower().startswith('location:'): loc=line.split(':',1)[1].strip()
  if line.lower().startswith('server:'): srv=line.split(':',1)[1].strip()
 sig=','.join(dict.fromkeys(x.decode() for x in re.findall(br'(?i)Axis|SAS|Airlock|Misdirected|no Route matched|Unauthorized|Forbidden|Service|check-login',body)))
 snippet=re.sub(r'\s+',' ',body[:180].decode('latin1','replace')).strip()
 return ip,st,len(body),srv,loc,sig or snippet
with concurrent.futures.ThreadPoolExecutor(max_workers=15) as ex:
 for row in ex.map(one,ips):
  ip,st,sz,srv,loc,sig=row
  print(f'{ip:16} status={st:7} size={sz:<6} server={srv:<18} loc={loc[:90]:<90} sig={sig[:120]}',flush=True)
