Skip to content

Instantly share code, notes, and snippets.

@Sy14r
Created February 24, 2020 19:43
Show Gist options
  • Save Sy14r/57cdae58a5476cb26c53b07034be66a0 to your computer and use it in GitHub Desktop.
Save Sy14r/57cdae58a5476cb26c53b07034be66a0 to your computer and use it in GitHub Desktop.
# Janky script to take hosts csv report data from Recon-NG and perform whois lookups on each IP and add org/descr info
# to each line of the resulting csv.
file='/path/to/recon-ng/hosts-report.csv'
while read line
do
HOST=$(echo $line | cut -d "," -f 1)
IP=$(echo $line | cut -d "," -f 2 | tr -d '"')
length=${#IP}
if [ $length -gt 0 ]
then
whoisdescr=$(whois $IP | grep -i 'descr:' | sed -e 's/descr://g' | tr "\n" " " | tr -s ' ' | sed -e's/^ //g')
whoisorg=$(whois $IP | grep -i 'orgname:' | sed -e 's/OrgName://g' | tr "\n" " " | tr -s ' ' | sed -e's/^ //g')
descrLen=${#whoisdescr}
orgLen=${#whoisorg}
if [ $descrLen -gt 0 ] && [ $orgLen -gt 0 ]]
then
echo -n "$HOST,\"$IP\",\"$whoisdescr $whoisorg\"\n"
elif [ $descrLen -gt 0 ]
then
echo -n "$HOST,\"$IP\",\"$whoisdescr\"\n"
elif [ $orgLen -gt 0 ]
then
echo -n "$HOST,\"$IP\",\"$whoisorg\"\n"
else
echo -n "$HOST,\"$IP\",\"NO ENRICHMENT DATA FOUND\"\n"
fi
else
echo "$HOST,\"$IP\",\"\""
fi
done < $file
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment