Ping sweep with classic fping on Linux

Jackbox

Active Member
Jan 2, 2016
197
96
74
Code:
#fping is a dependency
apt install fping -y

#perform scan of /24 meaning first 24 bits unchanging
#24/8 bits is 3 bytes so first 3 octets unchanging
#same.same.same.SWEEP
#depending on subnet, .0 network identifier, .255 broadcast
#meaning 1-254 typically scanned

LOCALNET1=`hostname -I | grep -oE "\b([0-9]{1,3}\.){3}[0-9]{1,3}\b" | grep -Ev '127|255|0.0' | sort -u`
TARGETRANGE=$LOCALNET1'/24'
fping -g $TARGETRANGE > scanned.hosts
cat scanned.hosts | grep " is alive" | grep -oE "\b([0-9]{1,3}\.){3}[0-9]{1,3}\b" > liveip.hosts

#print results of scan
echo "######### RESULTS START ###" && wc -l *hosts | sed '$d' && echo "#########
RESULTS END ###"
echo done
sleep 1

Simply copy/paste into SSH session or make this into a .sh to wget onto network you are checking. Keep in mind, on some hosts you may have to wait for fping to complete depending on how slow the network is for ping responses.

Nmap also permits the same, an alternative method from hostname is ifconfig.

ifconfig | grep -oE "\b([0-9]{1,3}\.){3}[0-9]{1,3}\b" | grep -Ev '127|255|0.0' | sort -u

If anyone finds a way to make this more efficient or simpler, let me know! Also if some of my logic is wrong please let me know because I always love learning more. Why sleep 1? Because I love sleep.

Why am I posting this? I am working on a web-based interface in various programming languages (PHP, Python, Bash) to make the best and fastest network health triage tool. Included features:
  1. host discovery
  2. port scanning
  3. fingerprinting
  4. uptime monitoring with email and text alerts
  5. log aggregation
  6. open source vulnerability scanning
Among other features.. so playing around with all the possible ways to fully automate common tasks like /24 discovery is a fun hobby as of late.

But why make something like this? Because most tools end you up like a sheep prodder. Why prod the sheep on foot when you can have a drone move sheep how you want?! Automation is critical to expediting security for both proactive and reactive measures. The ability to have the most beautiful balance between a blue team and red team service quickly deployable and accessible through a mobile-friendly web interface is light years forward from where most tools seem to be. Especially for free!
 
Last edited:
Top