#!/bin/bash
cd /root/recon
ls -la respA.tsv 2>/dev/null
awk -F'\t' 'index($5,"f5")>0{print $1}' respA.tsv 2>/dev/null | sort -u > f5A.txt
wc -l f5A.txt
cut -f1 f5_ui2.txt | sort -u > /tmp/ui_done.txt
comm -23 f5A.txt /tmp/ui_done.txt > f5A_todo.txt
wc -l f5A_todo.txt
chk() {
  h=$1
  out=$(curl -sk -m 8 -A 'Mozilla/5.0' -o /tmp/f5d_$h.txt -w '%{http_code}' "https://$h/f5-oauth2/v1/userinfo" 2>/dev/null)
  body=$(head -c 90 /tmp/f5d_$h.txt 2>/dev/null | tr '\n' ' ')
  { [ "$out" != "000" ] && [ "$out" != "404" ]; } && echo "$h $out $body"
  rm -f /tmp/f5d_$h.txt
}
export -f chk
if [ -s f5A_todo.txt ]; then
  cat f5A_todo.txt | xargs -P16 -I{} bash -c 'chk {}' > f5_ui3.txt 2>&1
  wc -l f5_ui3.txt
  awk '{print $2}' f5_ui3.txt | sort | uniq -c | sort -rn | head
  awk '$2=="401"' f5_ui3.txt | head -5
  grep -aiE 'bearer|\{"error|access_token' f5_ui3.txt | head -5
fi
echo PFDONE
