SHARE
TWEET

aramosf

a guest Feb 4th, 2009 679 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/bash
  2. # Tue Dec 30 12:38:32 CET 2008 <aramosf @ unsec.net>
  3. #
  4. # TODO:
  5. # - Bucle para los alias.
  6. # - Servicio web?
  7.  
  8. APPID="7066FAEB6435DB963AE3CD4AC79CBED8B962779C"
  9.  
  10.  
  11. function usage() {
  12.   cat << EOF
  13.   $0 <-h IP> [-n] [-g NUM]
  14.      -h <host> : IP/Host address to check
  15.      -n        : Don't check from vhosts with A record
  16.      -g <num>  : Number of results to get (default 100)
  17. EOF
  18. exit 0
  19. }
  20.  
  21. URL="http://api.search.live.net/json.aspx"
  22. DNS=1; HITS=0; HOST=0
  23.  
  24. while getopts ":h:g:n" options; do
  25.   case $options in
  26.          h ) HOST=$OPTARG;;
  27.          g ) HITS=$OPTARG;;
  28.          n ) DNS=0;;
  29.          : ) echo "-$OPTARG requires an argument."; usage;;
  30.          \? ) usage;;
  31.  esac
  32. done
  33.  
  34. if [ "$HOST" == "0" ]; then
  35.    echo "No IP/Host specified"
  36.    usage
  37. fi
  38. if [[ $HOST =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]
  39.   then
  40.         IP=$HOST
  41.   else
  42.         IP=`host $HOST|awk 'BEGIN {NF = 1} /address/{print $4}'`
  43.         if [ $( echo "$IP"|wc -l) -gt 1 ]; then
  44.                 echo $HOST have an alias. Using first IP.
  45.                 IP=`echo "$IP"|head -1`
  46.         fi
  47. fi
  48. if [ -z $IP ]; then echo "Error with IP: \"$IP\""; exit 0; fi
  49.  
  50. RSLTS=`curl -s "$URL?Appid=$APPID&sources=web&query=IP:\"$IP\""|sed -e \
  51.   's/.*Total":\([0-9]*\).*/\1/'`
  52. echo "Number of results: $RSLTS. IP: $IP"
  53.  
  54. if [ $RSLTS -gt 1000 ] && [ $HITS == 0 ]; then
  55.  echo "Too much results, using first 100"
  56.  RSLTS=100
  57. fi
  58. if [ $HITS -gt 0 ]; then
  59.  echo "Forcing to get $HITS results"
  60.  RSLTS=$HITS;
  61. fi
  62.  
  63. # Let's go.
  64. echo "------------------------------------"
  65. OFFSET=0
  66. while [ $OFFSET -lt $(( $RSLTS + 50 )) ]; do
  67.  DA=$(curl -s \
  68.  "$URL?Appid=$APPID&Web.Count=50&sources=web&query=IP:\"$IP\"+$str&Web.Offset=$OFFSET" \
  69.  | sed -e 's|\\/|/|g' -e 's|,|\n|g'|grep '"Url":' \
  70.  | sed -e 's|.*//\([^/|^"]*\)"*.*|\1|')
  71.  DB="$DB\n$DA"
  72.  str=`echo -e "$DB"|sort|uniq -c|sort -gr \
  73.    |awk '$2~/[aA-zZ]/ {print "-site:"$2}'|head -15|tr '\n' '+'`
  74.  OFFSET=$(( $OFFSET + 50 ))
  75. done
  76.  
  77. if [ $DNS == 1 ]; then
  78.  for host in `echo -e "$DB" | sort | uniq`; do
  79.         ADDR=`host $host| awk 'BEGIN {NF = 1}/address/{print $4}'`
  80.         if [ "$ADDR" == "$IP" ]; then
  81.                 AA="$AA $host"
  82.         else
  83.                 if [ -z "$ADDR" ]; then ADDR="No_address"; fi
  84.                 BB="$BB $host:${ADDR}"
  85.         fi
  86.  done
  87.  A=`echo -e "$AA" |sort | uniq`
  88.  echo $A \
  89.  |awk '{ for (idx=1; $idx; i++) {printf "%-39s %-39s\n", $(idx++),$(idx++); }}'
  90.  echo Total: `echo "$AA"|tr ' ' '\n'|sort|uniq|sed -e 1d|wc -l`
  91.  ETOTAL=`echo -e "$BB" |tr ' ' '\n'|sort |uniq|sed -e 1d|wc -l`
  92.  if [ $ETOTAL -gt 0 ]; then
  93.   echo -e "\nWith errors"
  94.   echo "------------------------------------"
  95.   echo -e "$BB" |tr ' ' '\n'|sort|uniq|sed -e 1d \
  96.      |awk -F: '{ printf "%-39s %-39s\n", $1,$2}'
  97.   echo "Total with errors: $ETOTAL"
  98.  else
  99.    echo -e "\nNo errors found"
  100.  fi
  101. else
  102.  A=`echo -e "$DB" |sort | uniq`
  103.  echo $A \
  104.  |awk '{ for (idx=1; $idx; i++) {printf "%-39 %-39\n", $(idx++),$(idx++); }}'
  105.  echo Total: `echo -e "$A" |sort | uniq|wc -l`
  106. fi
RAW Paste Data
Top