Najszybszy sposób na pingowanie zasięgu sieci i zwracanie responsywnych hostów?

Ograniczenia:
1. Prędkość ma znaczenie.
2. Mogę ping raz.

Zastanawiam się, czy używać Pythona czy shellscriptingu. Czy istnieje metoda szybsza niż bash?

Oto aktualny kod,

for ip in $(seq int1 int2); do
    ping -c 1 xxx.xxx.xxx.$ip | grep "bytes from" &
done
Coś szybszego niż to?
Author: Roman Newaza, 2012-12-26

6 answers

Powinieneś użyć NMAP:

nmap -T5 -sP 192.168.0.0-255
 69
Author: Roman Newaza,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2016-03-24 09:37:37

Poniższy (zły) kod działa ponad dwa razy szybciej niż metoda nmap

for i in {1..254} ;do (ping 192.168.1.$i -c 1 -w 5  >/dev/null && echo "192.168.1.$i" &) ;done

Trwa około 10 sekund, gdzie standardowa nmap

nmap -sP 192.168.1.1-254
Trwa 25 sekund...
 25
Author: Mike Redrobe,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2014-02-16 17:20:57

Wypróbuj to, aby uzyskać unikalną listę.

ping -c 5 -b 10.10.0.255 | grep 'bytes from' | awk '{ print $4 }' | sort | uniq

Inna metoda (pobiera żywe hosty):

fping -ag 192.168.1.0/24

 12
Author: Sunny R Gupta,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2012-12-26 09:49:31

Wypróbuj oba te polecenia i przekonaj się, dlaczego arp jest szybszy:

PING:

Dla ip w $(seq 1 254); do ping-c 1 10.185.0.$ip > /dev / null; [$? -eq 0] & & echo " 10.185.0.$ip UP"//:; done

ARP:

Dla ip w $(seq 1 254); do arp-n 10.185.0.$adres ip / grep; [$? -eq 0] & & echo " 10.185.0.$ip UP"//:; done

 3
Author: brendonmartino,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2016-03-10 20:02:47

Ten skrypt działa na Git Bash (MINGW64) w systemie Windows i zwraca wiadomość w zależności od wyniku Pingu.

#!/bin/bash
#$1 should be something like "19.62.55"

if [ -z "$1" ]
  then
    echo "No identify of the network supplied, i.e. 19.62.55"
else
    ipAddress=$1

    for i in {1..256} ;do 
    (
        {
        ping -w 5 $ipAddress.$i ; 
        result=$(echo $?);
        } &> /dev/null


        if [ $result = 0 ]; then
            echo Successful Ping From : $ipAddress.$i
        else
            echo Failed Ping From : $ipAddress.$i
        fi &);
    done

fi
 0
Author: DiegoRG,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2018-02-02 13:33:58

Jest to kod Pythona dla ping w zakresie 192.168.0.0-192.168.0.100 . Możesz zmienić pętlę, jak wygodnie.

# -*- coding: utf-8 -*-
import socket
import os
import sys

up_ip =[] #list to store the ip-addresses of server online
for x in range(100):  #here range is 0-100. You can change the range according to your comfort
    server_ip = '192.168.0.'+ str(x)
    rep = os.system('ping -c 1 ' + server_ip)

    if rep == 0:
        upip.append(server_ip)
        print '*******************Server Is Up****************\n'
    else:
        print 'server is down \n'

print up_ip
 0
Author: Vilas Joshi,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2018-07-11 07:32:33