ip-generator.sh 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #! bin/bash
  2. #IP generator
  3. VERSION="V1.2"
  4. #Generator to find all ip's in a range
  5. #Copy Right: Deben Oldert
  6. #Remove existing users file
  7. echo "IP generator"
  8. echo "Copy right: Deben Oldert"
  9. echo "Version: $VERSION"
  10. rm -f /users; touch /users
  11. #Ask the ip range
  12. echo "Enter your start ip"
  13. read firstip
  14. echo "Enter your end ip"
  15. read secondip
  16. #Split the ip strings into array's
  17. IFS='.' read -a first <<< "$1firstip"
  18. IFS='.' read -a second <<< "$secondip"
  19. #Set i for the counter
  20. i=0
  21. #Start looping
  22. for (( a=${first[0]}; a<=${second[0]}; a++ ))
  23. do
  24. for (( b=${first[1]}; b<=${second[1]}; b++ ))
  25. do
  26. for (( c=${first[2]}; c<=${second[2]}; c++ ))
  27. do
  28. #Set max ip value to 255 if needed
  29. if [ $c -lt ${second[2]} ]
  30. then
  31. DMAX=255
  32. else
  33. DMAX=${second[3]}
  34. fi
  35. #Set min ip value to 0 if needed
  36. if [ $c -gt ${first[2]} ]
  37. then
  38. DMIN=0
  39. else
  40. DMIN=${first[3]}
  41. fi
  42. for (( d=$DMIN; d<=$DMAX; d++ ))
  43. do
  44. #echo "$a.$b.$c.$d"
  45. #Put new line with ip in users file
  46. echo -e "$a.$b.$c.$d\r\n" >> /users
  47. #Ad 1 for the counter
  48. i=$((i+1))
  49. done
  50. done
  51. done
  52. done
  53. #Say it!
  54. echo "Found $i ip addresses in this range"