getips.sh 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #!/bin/bash
  2. INPUT=data/AS.csv
  3. CDNS=data/CDN.csv
  4. OLDIFS=$IFS
  5. IFS=,
  6. programname=$0
  7. LIMIT="none"
  8. build_rules () {
  9. echo "$company"
  10. whois -h whois.radb.net -- "-i origin ${as}" | grep ^route | while read -r ip; do
  11. ip=${ip//[[:blank:]]/}
  12. ip=${ip#"route"}
  13. ip=${ip#"6:"}
  14. ip=${ip#":"}
  15. ip=${ip//[[:blank:]]/}
  16. echo "$ip" >> file_$company
  17. done
  18. }
  19. if [ $# -eq 0 ]
  20. then
  21. echo "No arguments supplied, blocking all of them"
  22. else
  23. LIMIT=$1
  24. fi
  25. if [[ $LIMIT == "--help" ]]; then
  26. echo "usage: sudo $programname [--company]"
  27. echo " --amazon blocks traffic to and from amazon servers"
  28. echo " --google blocks traffic to and from google servers"
  29. echo " --facebook blocks traffic to and from facebook servers"
  30. echo " --help display help"
  31. echo " --microsoft blocks traffic to and from microsoft servers"
  32. echo " --apple blocks traffic to and from apple servers"
  33. echo " --fascist blocks all companies including CDNS"
  34. exit 1
  35. fi
  36. [ ! -f $INPUT ] && { echo "$INPUT file not found"; exit 99; }
  37. while read company as
  38. do
  39. if [[ $LIMIT == "--"$company || $LIMIT == "none" || $LIMIT == "--fascist" ]]; then
  40. build_rules "$as" "$company"
  41. fi
  42. done < $INPUT
  43. if [[ $LIMIT == "--fascist" ]]; then
  44. [ ! -f $CDNS ] && { echo "$CDNS file not found"; exit 99; }
  45. while read company as
  46. do
  47. build_rules "$as" "$company"
  48. done < $CDNS
  49. fi