'How can MTR scriptly tracroutes multiple hosts ( one network )?

mtr

As picture showed above, since mtr can only traceroute one host once, how can I "scan" the whole network (172.16.0.0/16) and find all the hosts which only got 2 hops, with a script? Thank you.



Solution 1:[1]

For those who may need it, the simple way: enter image description here

Solution 2:[2]

#!/bin/bash
  
touch result

for ip in 172.16.{35..254}.{1..254}
do
        echo "Trying $ip ... "
        hops=$( mtr -c 5 -r -n4 -T $ip | wc -l )
        if [[ "$hops" == 4 ]]; then
                echo "Yes!"
                echo $ip >> result
        fi
done

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 user1150125
Solution 2 Brandon