Sken IP adres na UBNT: Porovnání verzí
Z Wiki UnArt Slavičín
Skočit na navigaciSkočit na vyhledávání
Bez shrnutí editace |
|||
Řádek 51: | Řádek 51: | ||
= Skript vše v jednom = | = Skript vše v jednom = | ||
#!/bin/bash | |||
# rozsah lokalnich IP adres | # rozsah lokalnich IP adres | ||
address="192.168.1." | address="192.168.1." | ||
Řádek 59: | Řádek 61: | ||
# cislo posledni IP adresy | # cislo posledni IP adresy | ||
end=254 | end=254 | ||
# pocet skenu najednou | |||
count=20 | |||
# interval mezi skeny | |||
sleep=5 | |||
# porty HTTP ke skenovani | # porty HTTP ke skenovani | ||
Řádek 64: | Řádek 72: | ||
iface=`ip addr | grep $address | awk '{print $NF}'`; | iface=`ip addr | grep $address | awk '{print $NF}'`; | ||
for i in `seq $start $end`; | |||
log="/tmp/scan.log" | |||
test_host () | |||
{ | |||
output="" | |||
ping -q -c1 -W1 $1 >/dev/null && output="ping" | |||
arping -q -c1 -w1 -I $iface $1 >/dev/null && output="$output arping" | |||
for port in $ports; | |||
do | |||
wget -qO- http://$1:$port >/dev/null 2>&1 && output="$output port $port " | |||
done | |||
if [ -n "$output" ]; | |||
then | |||
echo "$1: $output" | |||
fi | |||
} | |||
greater () | |||
{ | |||
if [ $1 -le $2 ]; | |||
then | |||
echo $1 | |||
else | |||
echo $2 | |||
fi | |||
} | |||
rm "$log" | |||
for i in `seq $start $count $end`; | |||
do | do | ||
from=$address$i | |||
to=`greater $((i+count)) $end` | |||
echo "$address$i - $address$to" | |||
for j in $(seq $i $to); | |||
do | |||
ip=$address$j | |||
test_host $ip >> "$log" & | |||
done | |||
sleep $sleep | |||
done | done | ||
cat "$log" |
Aktuální verze z 10. 10. 2023, 06:19
Přes SSH v konzoli, vždy upravte proměnné:
address = rozsah lokálních IP adres
start = číslo počáteční IP adresy
end = číslo koncové IP adresy
port = port, na kterém běží webové rozhraní (pouze HTTP)
ping
address="192.168.1."; start=1; end=254; for i in `seq $start $end`; do up=`ping -c1 -W1 $address$i | grep "1 packets received" | wc -l`; if [ "$up" -eq 1 ]; then echo $address$i; fi; done
arping
address="192.168.1."; start=1; end=254; iface=`ip addr | grep $address | awk '{print $NF}'`; for i in `seq $start $end`; do up=`arping -c1 -w1 -I $iface $address$i | grep "Received 1 replies" | wc -l`; if [ "$up" -eq 1 ]; then echo $address$i; fi; done
wget
address="192.168.1."; start=1; end=254; port=80; for i in `seq $start $end`; do wget -qO- http://$address$i:$port >/dev/null 2>&1 && echo $address$i; done
Skript vše v jednom
#!/bin/bash # rozsah lokalnich IP adres address="192.168.1." # cislo prvni IP adresy start=1 # cislo posledni IP adresy end=254 # pocet skenu najednou count=20 # interval mezi skeny sleep=5 # porty HTTP ke skenovani ports="80 8080" iface=`ip addr | grep $address | awk '{print $NF}'`; log="/tmp/scan.log" test_host () { output="" ping -q -c1 -W1 $1 >/dev/null && output="ping" arping -q -c1 -w1 -I $iface $1 >/dev/null && output="$output arping" for port in $ports; do wget -qO- http://$1:$port >/dev/null 2>&1 && output="$output port $port " done if [ -n "$output" ]; then echo "$1: $output" fi } greater () { if [ $1 -le $2 ]; then echo $1 else echo $2 fi } rm "$log" for i in `seq $start $count $end`; do from=$address$i to=`greater $((i+count)) $end` echo "$address$i - $address$to" for j in $(seq $i $to); do ip=$address$j test_host $ip >> "$log" & done sleep $sleep done cat "$log"