Advertisement
Guest User

Untitled

a guest
Apr 11th, 2020
238
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.90 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. if ! dpkg -s fping &>/dev/null; then
  4. echo "[!] Install fping: sudo apt-get install fping"
  5. exit 1
  6. fi
  7.  
  8. if ! dpkg -s parallel &>/dev/null; then
  9. echo "[!] Install parallel: sudo apt-get install parallel"
  10. exit 1
  11. fi
  12.  
  13. ip_list=( "${@}" )
  14.  
  15. until [[ "${#ip_list[@]}" -gt 0 ]]; do
  16. echo "[!] Enter list of IP's and press ENTER then CTRL+D when done."
  17. ip_list=( $(cat -) )
  18. done
  19.  
  20. echo -e "\n### Checking Hosts ###\n"
  21.  
  22. fping_ip_list=$(fping "${ip_list[@]}" &>/dev/stdout)
  23.  
  24. for ip in "${ip_list[@]}"; do
  25. grep_from_fping=$( <<< "${fping_ip_list}" grep "^${ip}" )
  26. if [[ "${grep_from_fping}" =~ "service not known" ]]; then
  27. invalid_ip_list+=( "${ip}" )
  28. elif [[ "${grep_from_fping}" =~ "is unreachable" ]]; then
  29. unreachable_ip_list+=( "${ip}" )
  30. elif [[ "${grep_from_fping}" =~ "is alive" ]]; then
  31. reachable_ip_list+=( "${ip}" )
  32. else
  33. echo "Something went wrong, shouldn't go this far"
  34. exit 1
  35. fi
  36. done
  37.  
  38. echo -e "\n######## Reachable Host List ########"
  39. printf "%s\n" "${reachable_ip_list[@]}"
  40.  
  41. echo -e "\n######## Unreachable Host List ########"
  42. printf "%s\n" "${unreachable_ip_list[@]}"
  43.  
  44. echo -e "\n######## Unknown Host / Invalid IP List ########"
  45. printf "%s\n" "${invalid_ip_list[@]}"
  46.  
  47. read -rp "What is the full path to the file you want to transfer? Example: /tmp/example_filename : " FILE_SOURCE
  48.  
  49. while [ ! -f "${FILE_SOURCE}" ]; do
  50. read -rp "File not found! Please enter the full path to the file again: " FILE_SOURCE
  51. done
  52.  
  53. scp_file() {
  54. file="${1}"
  55. host="${2}"
  56. if /usr/bin/scp "${file}" idirect@"${host}":/tmp/ &>/dev/null; then
  57. echo "[!] SCP: ${file} -> ${host} - OK"
  58. else
  59. echo "[!] SCP: ${file} -> ${host} - FAILED"
  60. fi
  61. }
  62.  
  63. export -f scp_file
  64. export FILE_SOURCE
  65. echo -e "\n## Starting Now ##\n"
  66. parallel -k --no-notice "scp_file ${FILE_SOURCE} " ::: "${reachable_ip_list[@]}"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement