Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2020
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.92 KB | None | 0 0
  1. #!/bin/bash
  2. #
  3. # v0.1
  4. #
  5. # Written by sabri@cluecentral.net
  6. #
  7. # ./findloss.sh <dst ip> <dst prt> <src port base> <packet size>
  8. #
  9. # The source port will be incremented by 1 until 10 failures have been
  10. # detected or until 500 probes have been transmitted. Example:
  11. #
  12. # ./findloss.sh 192.168.2.200 80 50000 1400
  13. #
  14. IP=$1
  15. PORT=$2
  16. BASE=$3
  17. if [ -z "$4" ]
  18. then
  19.     SIZE=512
  20. else
  21.     SIZE=$4
  22. fi
  23. LIST=""
  24. NUM=0
  25. OUT="/tmp/tcpscan.$RANDOM"
  26. mkdir $OUT
  27.  
  28. if [ -z "$3" ]
  29. then
  30.     echo "$0 IP PORT BASE SIZE(optional default 512)"
  31.     exit
  32. fi
  33.  
  34. END=`expr $BASE + 500`
  35.  
  36. echo ""
  37. echo "Starting the test. Our CLI will look like:"
  38. echo "nping -c 10 --rate 20 -g [$BASE-$END]  --tcp --flags A -p $PORT --data-length $SIZE --dest-ip $IP"
  39. echo ""
  40. for i in `seq $BASE $END`
  41. do
  42.     RES=`nping -c 10 --rate 20 -g $i --tcp --flags A -p $PORT --data-length $SIZE --dest-ip $IP | grep Lost | cut -f4 -d: | awk '{ print $1}'`
  43.     if [ "$RES" -gt 2 ]
  44.     then
  45.         LIST="$LIST $i"
  46.         /bin/echo -n "."
  47.     else
  48.         /bin/echo -n "!"
  49.     fi
  50.  
  51.     NUM=`echo $LIST | wc | awk '{ print $2}'`
  52.     if [ $NUM -gt 9 ]
  53.     then
  54.         echo ""
  55.         echo ""
  56.         echo "Got 10 failures, exiting to the next step"
  57.         break
  58.     fi
  59. done
  60. echo ""
  61. echo "Running tcptraceroute with source ports: $LIST"
  62. echo ""
  63. /bin/echo -n "Working on "
  64. for i in $LIST
  65. do
  66.     /bin/echo -n "$i..."
  67.     traceroute -l $SIZE -n -T -w 1 -q 10 -z 11 --sport=$i -p $PORT $IP 1472 | grep -v trace | sed -e 's/\*//g' | awk '{ print $2}' > $OUT/$i
  68.  
  69. done
  70. echo "Done!"
  71. echo ""
  72. WINNER=`md5sum $OUT/* | awk '{print $1}' | sort | uniq -c | sort -n | tail -n1 | awk '{ print $2}'`
  73. WINNERCNT=`md5sum $OUT/* | awk '{print $1}' | sort | uniq -c | sort -n | tail -n1 | awk '{ print $1}'`
  74. for i in $LIST
  75. do
  76.     TEST=`md5sum $OUT/$i | awk '{print $1}'`
  77.     if [ "$TEST" == "$WINNER" ]
  78.     then
  79.         echo "The most suspect path with $WINNERCNT hits is:"
  80.         echo ""
  81.         cat $OUT/$i
  82.         break
  83.     fi
  84. done
  85.  
  86. echo ""
  87. echo "The raw output can be found in $OUT"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement