0

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 ?

2 Answers 2

1

No need for a script. nmap Install 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
3
  • without need to any package or utility
    – nux
    Jan 29, 2014 at 23:44
  • @nux If that was a requirement for you then that belongs in your question. And it's sad you didn't mention it in there earlier on as I have taken the time to provide an answer without that requirement being listed...
    – gertvdijk
    Jan 29, 2014 at 23:46
  • OK you are right me friend am sorry for your time , and your answer is excellent please keep it don't delete it
    – nux
    Jan 29, 2014 at 23:47
1

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .