Created
February 26, 2023 16:43
-
-
Save rxerium/e247216178a87788d100849f5b9e8fce to your computer and use it in GitHub Desktop.
Ping Hosts on the network and output to a file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ---------- | |
#!/bin/bash | |
# Pings all devices on the .30 ranges and outputs all active hosts to the online_hosts.txt file | |
# Useful when creating hosts files with Ansible playbooks | |
# ---------- | |
for i in {1..254} | |
do | |
ping -c 1 10.0.30.$i > /dev/null 2>&1 | |
if [ $? -eq 0 ]; then | |
hostname=$(nslookup 10.0.30.$i | grep "name =" | awk '{print $4}') | |
echo "10.0.30.$i $hostname" >> online_hosts.txt | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment