I couldn't come up with any better ideas, so here is a bash implementation of the traceroute method. Seems to work:
#!/bin/bash
A="ec2-75-101-201-203.compute-1.amazonaws.com" # node in us-east-1a
B="ec2-75-101-228-202.compute-1.amazonaws.com" # node in us-east-1b
C="ec2-174-129-138-71.compute-1.amazonaws.com" # node in us-east-1c
for mirror in $A $B $C; do
HOPS="`tracepath -n $mirror | grep hops | awk '{ print $5 }'`"
# checking for an int is not pretty in bash
[ "$HOPS" -gt 0 ] 2>&- && echo "$HOPS $mirror"
done | sort -n | head -n 1 | awk '{ print $2 }'
The host that ran this command was on us-east-1c, and selected $C correctly each time.
I couldn't come up with any better ideas, so here is a bash implementation of the traceroute method. Seems to work:
#!/bin/bash
A="ec2- 75-101- 201-203. compute- 1.amazonaws. com" # node in us-east-1a 75-101- 228-202. compute- 1.amazonaws. com" # node in us-east-1b 174-129- 138-71. compute- 1.amazonaws. com" # node in us-east-1c
B="ec2-
C="ec2-
for mirror in $A $B $C; do
HOPS="`tracepath -n $mirror | grep hops | awk '{ print $5 }'`"
# checking for an int is not pretty in bash
[ "$HOPS" -gt 0 ] 2>&- && echo "$HOPS $mirror"
done | sort -n | head -n 1 | awk '{ print $2 }'
The host that ran this command was on us-east-1c, and selected $C correctly each time.
root@ubuntu:~# ./close-host.sh 129-138- 71.compute- 1.amazonaws. com
ec2-174-
Example tracepath output:
ec2-75- 101-201- 203.compute- 1.amazonaws. com 31-39-00- 9D-23.compute- 1.internal (10.254.162.209) 0.092ms pmtu 1500 254-160- 160.compute- 1.internal (10.254.160.160) 0.099ms 254-160- 160.compute- 1.internal (10.254.160.160) 0.055ms 101-160- 160.compute- 1.amazonaws. com (75.101.160.160) 0.522ms 182-232- 13.usma2. compute. amazonaws. com (216.182.232.13) 1.077ms 101-160- 33.compute- 1.amazonaws. com (75.101.160.33) 1.171ms 252-128- 156.compute- 1.internal (10.252.128.156) 1.037ms 31-38-00- 7D-64.compute- 1.internal (10.252.130.146) 1.074ms reached
1: domU-12-
1: dom0-10-
1: dom0-10-
2: 10.254.160.2 (10.254.160.2) 0.979ms
3: ec2-75-
4: othr-216-
5: ec2-75-
6: dom0-10-
7: domU-12-
Resume: pmtu 1500 hops 7 back 58
ec2-75- 101-228- 202.compute- 1.amazonaws. com 31-39-00- 9D-23.compute- 1.internal (10.254.162.209) 0.055ms pmtu 1500 254-160- 160.compute- 1.internal (10.254.160.160) 0.061ms 254-160- 160.compute- 1.internal (10.254.160.160) 0.053ms 101-160- 176.compute- 1.amazonaws. com (75.101.160.176) 0.397ms 182-232- 15.usma2. compute. amazonaws. com (216.182.232.15) 0.823ms 182-224- 18.usma1. compute. amazonaws. com (216.182.224.18) 1.191ms 101-160- 113.compute- 1.amazonaws. com (75.101.160.113) 1.434ms 124-167. ec2.internal (10.251.124.167) 1.094ms 127-65. ec2.internal (10.251.127.65) 1.201ms reached
1: domU-12-
1: dom0-10-
1: dom0-10-
2: 10.254.160.2 (10.254.160.2) 0.728ms
3: ec2-75-
4: othr-216-
5: othr-216-
6: ec2-75-
7: ip-10-251-
8: ip-10-251-
Resume: pmtu 1500 hops 8 back 57
ec2-174- 129-138- 71.compute- 1.amazonaws. com 31-39-00- 9D-23.compute- 1.internal (10.254.162.209) 0.064ms pmtu 1500 254-160- 160.compute- 1.internal (10.254.160.160) 0.069ms 254-160- 160.compute- 1.internal (10.254.160.160) 0.055ms 254-164- 152.compute- 1.internal (10.254.164.152) 0.305ms 31-39-00- A1-A3.compute- 1.internal (10.254.166.81) 0.467ms reached
1: domU-12-
1: dom0-10-
1: dom0-10-
2: 10.254.160.2 (10.254.160.2) 0.889ms
3: dom0-10-
4: domU-12-
Resume: pmtu 1500 hops 4 back 61