Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- if ! dpkg -s fping &>/dev/null; then
- echo "[!] Install fping: sudo apt-get install fping"
- exit 1
- fi
- if ! dpkg -s parallel &>/dev/null; then
- echo "[!] Install parallel: sudo apt-get install parallel"
- exit 1
- fi
- ip_list=( "${@}" )
- until [[ "${#ip_list[@]}" -gt 0 ]]; do
- echo "[!] Enter list of IP's and press ENTER then CTRL+D when done."
- ip_list=( $(cat -) )
- done
- echo -e "\n### Checking Hosts ###\n"
- fping_ip_list=$(fping "${ip_list[@]}" &>/dev/stdout)
- for ip in "${ip_list[@]}"; do
- grep_from_fping=$( <<< "${fping_ip_list}" grep "^${ip}" )
- if [[ "${grep_from_fping}" =~ "service not known" ]]; then
- invalid_ip_list+=( "${ip}" )
- elif [[ "${grep_from_fping}" =~ "is unreachable" ]]; then
- unreachable_ip_list+=( "${ip}" )
- elif [[ "${grep_from_fping}" =~ "is alive" ]]; then
- reachable_ip_list+=( "${ip}" )
- else
- echo "Something went wrong, shouldn't go this far"
- exit 1
- fi
- done
- echo -e "\n######## Reachable Host List ########"
- printf "%s\n" "${reachable_ip_list[@]}"
- echo -e "\n######## Unreachable Host List ########"
- printf "%s\n" "${unreachable_ip_list[@]}"
- echo -e "\n######## Unknown Host / Invalid IP List ########"
- printf "%s\n" "${invalid_ip_list[@]}"
- read -rp "What is the full path to the file you want to transfer? Example: /tmp/example_filename : " FILE_SOURCE
- while [ ! -f "${FILE_SOURCE}" ]; do
- read -rp "File not found! Please enter the full path to the file again: " FILE_SOURCE
- done
- scp_file() {
- file="${1}"
- host="${2}"
- if /usr/bin/scp "${file}" idirect@"${host}":/tmp/ &>/dev/null; then
- echo "[!] SCP: ${file} -> ${host} - OK"
- else
- echo "[!] SCP: ${file} -> ${host} - FAILED"
- fi
- }
- export -f scp_file
- export FILE_SOURCE
- echo -e "\n## Starting Now ##\n"
- parallel -k --no-notice "scp_file ${FILE_SOURCE} " ::: "${reachable_ip_list[@]}"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement