0

I created a bash script that loops through a list of servers and traceroutes to them.

Here is what my source file looks like:

traceroute to speed.actaccess.net (72.36.7.94), 15 hops max, 60 byte packets
 1  _gateway (10.0.2.2)  0.397 ms  0.367 ms  0.364 ms
 2  10.36.85.221 (10.36.85.221)  2.554 ms  2.550 ms  2.545 ms
 3  69-42-239-254.rrt.stellarllc.net (69.42.239.254)  3.264 ms  3.260 ms *
 4  162.211.40.213 (162.211.40.213)  3.247 ms  3.242 ms  3.237 ms
 5  100ge1-cns-e.511.stellarllc.net (162.211.40.209)  14.764 ms  14.751 ms  14.745 ms
 6  as30110.micemn.net (206.108.255.176)  14.353 ms  14.330 ms  14.780 ms
 7  72-36-7-149.dynamic.range.net (72.36.7.149)  39.047 ms  41.488 ms  41.465 ms
 8  72-36-7-18.dynamic.range.net (72.36.7.18)  39.894 ms  41.449 ms  41.415 ms
 9  speed.actaccess.net (72.36.7.94)  41.408 ms  41.402 ms  41.352 ms
traceroute to speed-torrington.vcn.com (209.193.66.138), 15 hops max, 60 byte packets
 1  _gateway (10.0.2.2)  1.169 ms  1.084 ms  1.068 ms
 2  10.36.85.221 (10.36.85.221)  4.877 ms  4.870 ms  4.858 ms
 3  69-42-239-254.rrt.stellarllc.net (69.42.239.254)  4.846 ms  4.830 ms  5.334 ms
 4  162.211.40.213 (162.211.40.213)  5.319 ms  5.304 ms  5.294 ms
 5  100ge1-cns-e.511.stellarllc.net (162.211.40.209)  17.790 ms  17.783 ms  17.773 ms
 6  as6939.micemn.net (206.108.255.52)  17.760 ms  14.921 ms  15.595 ms
 7  * * *
 8  100ge8-1.core1.den1.he.net (184.105.222.93)  32.439 ms  37.128 ms  37.122 ms
 9  port-channel1.core2.den1.he.net (184.105.80.150)  38.232 ms * *
10  66.198.192.75 (66.198.192.75)  37.097 ms  36.706 ms  36.665 ms
11  66.198.192.81 (66.198.192.81)  32.208 ms  36.650 ms  36.645 ms
12  172.18.8.118 (172.18.8.118)  49.134 ms  49.488 ms  49.480 ms
13  speed-torrington.vcn.com (209.193.66.138)  48.586 ms  49.087 ms  49.079 ms
traceroute to sp1.guam.ite.net (202.123.136.76), 15 hops max, 60 byte packets
 1  _gateway (10.0.2.2)  0.469 ms  0.426 ms  0.419 ms
 2  10.36.85.221 (10.36.85.221)  2.182 ms  2.176 ms  2.093 ms
 3  69-42-239-254.rrt.stellarllc.net (69.42.239.254)  2.510 ms  2.502 ms  2.496 ms
 4  162.211.40.213 (162.211.40.213)  2.776 ms  3.229 ms  3.220 ms
 5  100ge1-cns-e.511.stellarllc.net (162.211.40.209)  14.733 ms  14.725 ms  14.718 ms
 6  as6939.micemn.net (206.108.255.52)  14.710 ms  14.209 ms  14.775 ms
 7  * * *
 8  100ge8-1.core1.den1.he.net (184.105.222.93)  31.650 ms  32.179 ms  32.173 ms
 9  port-channel10.core2.slc1.he.net (72.52.92.42)  44.454 ms * *
10  port-channel3.core3.lax2.he.net (184.104.197.62)  61.911 ms * *
11  100ge0-30.core2.lax2.he.net (184.104.196.37)  60.074 ms  60.800 ms  61.265 ms
12  100ge4-2.core1.hnl1.he.net (184.104.193.234)  106.413 ms  107.134 ms  107.122 ms
13  100ge0-36.core1.gum1.he.net (184.105.223.250)  174.245 ms  175.941 ms  175.936 ms
14  64.71.131.186 (64.71.131.186)  169.453 ms  170.536 ms  170.517 ms

I've been trying to do the following to the source file:

  1. Separate each server into it's own file.

File #1:

traceroute to speed.actaccess.net (72.36.7.94), 15 hops max, 60 byte packets
 1  _gateway (10.0.2.2)  0.397 ms  0.367 ms  0.364 ms
 2  10.36.85.221 (10.36.85.221)  2.554 ms  2.550 ms  2.545 ms
 3  69-42-239-254.rrt.stellarllc.net (69.42.239.254)  3.264 ms  3.260 ms *
 4  162.211.40.213 (162.211.40.213)  3.247 ms  3.242 ms  3.237 ms
 5  100ge1-cns-e.511.stellarllc.net (162.211.40.209)  14.764 ms  14.751 ms  14.745 ms
 6  as30110.micemn.net (206.108.255.176)  14.353 ms  14.330 ms  14.780 ms
 7  72-36-7-149.dynamic.range.net (72.36.7.149)  39.047 ms  41.488 ms  41.465 ms
 8  72-36-7-18.dynamic.range.net (72.36.7.18)  39.894 ms  41.449 ms  41.415 ms
 9  speed.actaccess.net (72.36.7.94)  41.408 ms  41.402 ms  41.352 ms

File #2:

traceroute to speed-torrington.vcn.com (209.193.66.138), 15 hops max, 60 byte packets
 1  _gateway (10.0.2.2)  1.169 ms  1.084 ms  1.068 ms
 2  10.36.85.221 (10.36.85.221)  4.877 ms  4.870 ms  4.858 ms
 3  69-42-239-254.rrt.stellarllc.net (69.42.239.254)  4.846 ms  4.830 ms  5.334 ms
 4  162.211.40.213 (162.211.40.213)  5.319 ms  5.304 ms  5.294 ms
 5  100ge1-cns-e.511.stellarllc.net (162.211.40.209)  17.790 ms  17.783 ms  17.773 ms
 6  as6939.micemn.net (206.108.255.52)  17.760 ms  14.921 ms  15.595 ms
 7  * * *
 8  100ge8-1.core1.den1.he.net (184.105.222.93)  32.439 ms  37.128 ms  37.122 ms
 9  port-channel1.core2.den1.he.net (184.105.80.150)  38.232 ms * *
10  66.198.192.75 (66.198.192.75)  37.097 ms  36.706 ms  36.665 ms
11  66.198.192.81 (66.198.192.81)  32.208 ms  36.650 ms  36.645 ms
12  172.18.8.118 (172.18.8.118)  49.134 ms  49.488 ms  49.480 ms
13  speed-torrington.vcn.com (209.193.66.138)  48.586 ms  49.087 ms  49.079 ms

File #3:

traceroute to sp1.guam.ite.net (202.123.136.76), 15 hops max, 60 byte packets
 1  _gateway (10.0.2.2)  0.469 ms  0.426 ms  0.419 ms
 2  10.36.85.221 (10.36.85.221)  2.182 ms  2.176 ms  2.093 ms
 3  69-42-239-254.rrt.stellarllc.net (69.42.239.254)  2.510 ms  2.502 ms  2.496 ms
 4  162.211.40.213 (162.211.40.213)  2.776 ms  3.229 ms  3.220 ms
 5  100ge1-cns-e.511.stellarllc.net (162.211.40.209)  14.733 ms  14.725 ms  14.718 ms
 6  as6939.micemn.net (206.108.255.52)  14.710 ms  14.209 ms  14.775 ms
 7  * * *
 8  100ge8-1.core1.den1.he.net (184.105.222.93)  31.650 ms  32.179 ms  32.173 ms
 9  port-channel10.core2.slc1.he.net (72.52.92.42)  44.454 ms * *
10  port-channel3.core3.lax2.he.net (184.104.197.62)  61.911 ms * *
11  100ge0-30.core2.lax2.he.net (184.104.196.37)  60.074 ms  60.800 ms  61.265 ms
12  100ge4-2.core1.hnl1.he.net (184.104.193.234)  106.413 ms  107.134 ms  107.122 ms
13  100ge0-36.core1.gum1.he.net (184.105.223.250)  174.245 ms  175.941 ms  175.936 ms
14  64.71.131.186 (64.71.131.186)  169.453 ms  170.536 ms  170.517 ms
  1. Loop through all those created files and compare the server IP in the first line, with the server IP in the last line. If they match, return true or something similar. So in my source file example, the first two tests files would be true, the last test file false.
  2. Get a listing of all the "true files" (files where the first server IP and last server IP match).

Any help is appreciated.

1 Answer 1

0

Figured it out.

Created a script to break each server into a file:

list=$(cat "servers.txt")
for name in $list
do
    echo $name > /home/kali/Downloads/servers/$name
done

Tracerouted each file and saved that to a new file:

for file in *
do
    name=$(echo $file)
    echo "doing " $name
    traceroute -m 9 -4 -I $name > $name.txt
done

Compared the IP of the server to the last hop of the traceroute:

for newfile in *.txt
do
    textname=$(echo $newfile)
    first=$(head -1 $textname | awk '{print $4}' | cut -d ',' -f 1)
    last=$(tail -1 $textname | awk '{print $3}')
    if [ $first = $last ]
    then
        echo "Yes -" $textname
    fi
done

Sample output:

Yes - blar-speed-01.gpcom.com.txt
Yes - boi-speedtest.tekfinity.net.txt
Yes - boise1.cabospeed.com.txt
Yes - denver-ec.speedtest.centurylink.net.txt
Yes - dexter1.cabospeed.com.txt
Yes - dfw-1.speedtest.ozarksgo.net.txt
Yes - eugene2.speedtest.centurylink.net.txt
Yes - helenast.northcentraltower.com.txt
Yes - htspeed3.hawaiiantel.net.txt
Yes - idahofalls1.cabospeed.com.txt
Yes - itdspeed2.nd.gov.txt
Yes - joplin1.cabospeed.com.txt
Yes - lightspeed.rainierconnect.com.txt
1
  • You can just do for name in $(cat servers.txt). And also, you should start double-quoting your variable calls. If somehow your variable contains spaces, it would split and would mess up your script.
    – annahri
    Aug 15, 2022 at 12:21

You must log in to answer this question.

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