Reputation:
I'm trying to ping multiple sub nets what I'm doing now is simply repeating the loop but I believe should be much simpler solution to do it in one loop
for i in 192.168.0.{1..254}
do
echo $1 >> live_host_list & disown
done
echo "net 192.168.0.0 Scanned"
echo "starting 10.0.0.0 network"
for i in 10.0.0.{1..254}
do
echo $1 >> live_host_list & disown
done
echo "net 10.0.0.0 Scanned"
Upvotes: 0
Views: 80
Reputation: 63972
You can very easily generate a list of IP's using perl
oneliner.
perl -MNet::IP -lnE '$ip=Net::IP->new($_) or warn "wrong input: $_";while($ip){say$ip++->ip()}'
You need the Net::IP module. The above code - formatted for easy reading:
perl -MNet::IP -lnE '
$ip = Net::IP->new($_) or warn "wrong input: $_";
while( $ip ) {
say$ip++->ip()
}'
The nice thing with the above is, it could accept many different inputs, e.g. you can use it as:
perl -MNet::IP -lnE '$ip=Net::IP->new($_)or warn "wrong input: $_";while($ip){say$ip++->ip()}' <<EOF
10.10.10.252 - 10.10.11.2
192.168.1.240/29
10.10.9.32 + 7
10.10.100.100
EOF
so, you can use as input
10.10.10.252 - 10.10.11.2
192.168.1.240/29
10.10.9.32 + 7
10.10.100.100
the above produces:
10.10.10.252
10.10.10.253
10.10.10.254
10.10.10.255
10.10.11.0
10.10.11.1
10.10.11.2
192.168.1.240
192.168.1.241
192.168.1.242
192.168.1.243
192.168.1.244
192.168.1.245
192.168.1.246
192.168.1.247
10.10.9.32
10.10.9.33
10.10.9.34
10.10.9.35
10.10.9.36
10.10.9.37
10.10.9.38
10.10.9.39
10.10.100.100
Upvotes: 0
Reputation:
subnetlist=("10.0.0." "10.0.1." "192.168.5.")
for subn in "${subnetlist[@]}"; do
echo "starting ${subn}0 network"
for oct in {1..254}; do
echo "${subn}${oct}" & disown
done
echo "net ${subnetlist}0 Scanned"
done
Upvotes: 0
Reputation: 11236
Could do this
for i in '192.168.0.' '10.0.0.';do
echo "starting $i.0 network"
for j in $i{1..254};do
echo $1 >> live_host_list $j & disown
done
echo "net $i.0 Scanned"
done
Upvotes: 1