我创建了一个 bash 脚本,该脚本循环遍历服务器列表并跟踪它们的路由。
这是我的源文件的样子:
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
我一直在尝试对源文件执行以下操作:
- 将每个服务器分成它自己的文件。
文件#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
文件#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
文件#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
- 循环遍历所有创建的文件,并将第一行中的服务器 IP 与最后一行中的服务器 IP 进行比较。如果它们匹配,则返回 true 或类似的内容。因此,在我的源文件示例中,前两个测试文件为 true,最后一个测试文件为 false。
- 获取所有“真实文件”(第一个服务器 IP 和最后一个服务器 IP 匹配的文件)的列表。
任何帮助表示赞赏。
答案1
弄清楚了。
创建一个脚本将每个服务器分解为一个文件:
list=$(cat "servers.txt")
for name in $list
do
echo $name > /home/kali/Downloads/servers/$name
done
跟踪每个文件并将其保存到一个新文件中:
for file in *
do
name=$(echo $file)
echo "doing " $name
traceroute -m 9 -4 -I $name > $name.txt
done
将服务器的IP与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
示例输出:
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