#Copy the existing Feed to a backup location
mv /var/www/html/RDNS-src.csv /var/www/html/RDNS-src.csv.bak
# We keep all IP Addresses that we have processed in /tmp/ipprocessed.txt
touch /tmp/ipprocessed.txt

# First Get a list of ip.src from our Broker. 
curl -s --user 'admin:netwitness' 'http://192.168.123.249:50103/sdk?msg=values&fieldName=ip.src&size=20000' |grep field |cut -f 2 -d ">" |cut -d "<" -f1 |grep -v rsyslogd | grep -v pts |grep -v ignored |grep -v \(\) >/tmp/RDNS-src.txt

while read p; do
  cmd=$(grep -ci "$p" /tmp/ipprocessed.txt)
  escape_p=$(echo "$p" |sed 's/\[/\\[/')
  cmd2=$(grep -ci "$escape_p" /tmp/ipprocessed.txt)
  if [ $cmd == "0" ] && [ $cmd2 == "0" ]; then
    #echo  "IP SRC "$p"  not previously seen so process it"
    #echo  "$p" >>/tmp/ipprocessed.txt
    OUTPUT=$(host $p  |grep -v "not found" |grep "domain name pointer"   |cut -d" " -f 5 | rev | cut -c 2- | rev |sed -n -e 'H;${x;s/\n/,/g;s/^,//;p;}')

   if [ "$OUTPUT" != "" ]; then
    echo "$p",$OUTPUT >>/var/www/html/RDNS-src.csv
   fi
  #else
  #  echo "UserAgent already in processed"
  fi
done </tmp/RDNS-src.txt
