Skip to content

Instantly share code, notes, and snippets.

@DonovanDiamond
Last active December 17, 2023 17:19
Show Gist options
  • Save DonovanDiamond/d99884d5481bfad4f44bc6a57c1d4863 to your computer and use it in GitHub Desktop.
Save DonovanDiamond/d99884d5481bfad4f44bc6a57c1d4863 to your computer and use it in GitHub Desktop.
#!/bin/bash
unifi_device_username="ubnt"
unifi_device_password="ubnt"
hosts_file="hosts.txt"
nmap_results_file="nmap-results.txt"
target_folder="logs"
if [ -f "$hosts_file" ]; then
echo "$hosts_file exists, not doing new scan for devices."
else
echo "Running nmap scan for devices with port 22 open to $nmap_results_file"
nmap -p 22 --open 192.168.1.0/24 -oG "$nmap_results_file" --stats-every 2s
echo "Filtering out ip addresses to $hosts_file"
grep "Up" "$nmap_results_file" | cut -d " " -f 2 > "$hosts_file"
fi
echo "Create the target folder if it doesn't exist"
mkdir -p "$target_folder"
echo "Loop over each host in the list and download the log file"
while read -r host; do
echo "Downloading log from $host"
mkdir "$target_folder/$host/"
sshpass -p "$unifi_device_password" \
scp -o StrictHostKeyChecking=accept-new -r \
"$unifi_device_username@$host:/var/log/message*" \
"$target_folder/$host/"
rmdir "$target_folder/$host/"
done < "$hosts_file"
echo "Done"
@DonovanDiamond
Copy link
Author

#grep -F "0a:00:00:00:00:00 IEEE" * | sed 's/^messages.old.//;s/^messages.//' | sed 's/:/\t/' | sort -k 3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment