I need a script that ping a group of ips and return as a result the online one , it will echo for example 10.10.10.10 is online
10.10.10.11 is online
10.10.10.15 is online
Without using any package or third party utility !
Any help ?
No need for a script. nmap can do it for you.
For example, to scan a 10.10.10.0/24 network, do
nmap -sn 10.10.10.0/24
This will report hosts being up based on responding to an ICMP Echo Request, known as 'ping'. An example output:
Starting Nmap 5.21 ( http://nmap.org ) at 2014-01-30 00:40 CET
Nmap scan report for 10.10.10.1
Host is up (0.0061s latency).
Nmap scan report for 10.10.10.2
Host is up (0.00071s latency).
Nmap scan report for android (10.10.10.112)
Host is up (0.0087s latency).
Nmap scan report for laptop (10.10.10.134)
Host is up (0.00037s latency).
Nmap scan report for 10.10.10.151
Host is up (0.00094s latency).
Nmap scan report for 10.10.10.203
Host is up (0.00060s latency).
Nmap done: 256 IP addresses (6 hosts up) scanned in 3.41 seconds
The script below will loop in a subnet ips and return as a result just the online :
#!/bin/bash
is_alive_ping()
{
ping -c 1 $1 > /dev/null
[ $? -eq 0 ] && echo Node with IP: $i is Online.
}
for i in 10.1.1.{1..255}
do
is_alive_ping $i & disown
done
Note change 10.1.1. to you subnet , a 1..255 tell the script to start from 10.1.1.1 and loop tell 10.1.1.255
Execute:
./ping_scan.sh