#!/bin/bash
cd /root/recon
UA='Mozilla/5.0'
echo '== PANOS retry clean =='
cut -f1 prod_panos.tsv | xargs -P8 -I{} bash -c '
  ip=$1
  code=$(curl -sk -m 8 -o /tmp/p2_$ip.txt -w "%{http_code}" "https://$ip/global-protect/portal/config.esp")
  if [ "$code" = "200" ]; then
    ver=$(grep -aoE "panos[^0-9]{0,10}[0-9]+\.[0-9]+\.[0-9]+(-h[0-9]+)?|sw-version[^,]{0,25}" /tmp/p2_$ip.txt | head -1)
    echo "$ip config200 $ver"
  fi
  rm -f /tmp/p2_$ip.txt' _ {} > pan_clean.txt 2>&1
echo "pan200: $(wc -l < pan_clean.txt)"; cat pan_clean.txt
echo '== BeyondTrust BRDF versions =='
grep -avi mitrade prod_beyondtrust.tsv | cut -f1 | xargs -P8 -I{} bash -c '
  ip=$1
  curl -sk -m 10 -o /tmp/br_$ip.bin "https://$ip/get_rdf?comp=sdcust&locale_code=en-us"
  ver=$(grep -aoE "2[0-9]\.[0-9]+\.[0-9]+" /tmp/br_$ip.bin | head -1)
  echo "$ip ver:${ver:-NA}"
  rm -f /tmp/br_$ip.bin' _ {} > bt_versions.txt 2>&1
cat bt_versions.txt
echo '== ScreenConnect versions =='
grep -aviE 'Sign in to view' prod_screenconnect.tsv | cut -f1 | xargs -P8 -I{} bash -c '
  ip=$1
  curl -sk -m 10 -o /tmp/sc2_$ip.txt "https://$ip/Login"
  ver=$(grep -aoE "version[\"'\'': =]+2[0-9]\.[0-9\.]+|ScreenConnect. [0-9]+\.[0-9.]+" /tmp/sc2_$ip.txt | head -1)
  echo "$ip ver:${ver:-NA}"
  rm -f /tmp/sc2_$ip.txt' _ {} > sc2_versions.txt 2>&1
cat sc2_versions.txt
echo DONE2
