summaryrefslogtreecommitdiff
path: root/scripts/vyatta-traceroute
diff options
context:
space:
mode:
authorJohn Southworth <john.southworth@vyatta.com>2011-08-17 19:36:11 -0500
committerJohn Southworth <john.southworth@vyatta.com>2011-10-27 17:11:28 -0500
commit1f8755e7fa091ae705eda151882424d4e95e1832 (patch)
tree9ef2a6ad90123d9e1ffda62b9eed1944a291a5f1 /scripts/vyatta-traceroute
parent909267c0ba0bf6c92e14150313e3e3f6958753ea (diff)
downloadvyatta-op-1f8755e7fa091ae705eda151882424d4e95e1832.tar.gz
vyatta-op-1f8755e7fa091ae705eda151882424d4e95e1832.zip
Initial traceroute rework checkin
(cherry picked from commit ce64904840bea3e716a7de3eca2618e63bcd87d1)
Diffstat (limited to 'scripts/vyatta-traceroute')
-rw-r--r--scripts/vyatta-traceroute28
1 files changed, 28 insertions, 0 deletions
diff --git a/scripts/vyatta-traceroute b/scripts/vyatta-traceroute
new file mode 100644
index 0000000..f6dff6b
--- /dev/null
+++ b/scripts/vyatta-traceroute
@@ -0,0 +1,28 @@
+#!/bin/bash
+ADDR=$1
+# Regular expressions for matching an ipv4 and ipv6 address
+# simple ipv4 matcher
+ip4regex="^(25[0-5]|2[0-4][0-9]|1[0-9]{1,2}|[1-9]?[0-9])(\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])){3}$"
+# based on IPv6 regex from here: http://forums.dartware.com/viewtopic.php?t=452
+ip6regex="^\s*((([0-9A-Fa-f]{1,4}:){7}([0-9A-Fa-f]{1,4}|:))|(([0-9A-Fa-f]{1,4}:){6}(:[0-9A-Fa-f]{1,4}|((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])(\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])){3})|:))|(([0-9A-Fa-f]{1,4}:){5}(((:[0-9A-Fa-f]{1,4}){1,2})|:((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])(\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])){3})|:))|(([0-9A-Fa-f]{1,4}:){4}(((:[0-9A-Fa-f]{1,4}){1,3})|((:[0-9A-Fa-f]{1,4})?:((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])(\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])){3}))|:))|(([0-9A-Fa-f]{1,4}:){3}(((:[0-9A-Fa-f]{1,4}){1,4})|((:[0-9A-Fa-f]{1,4}){0,2}:((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])(\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])){3}))|:))|(([0-9A-Fa-f]{1,4}:){2}(((:[0-9A-Fa-f]{1,4}){1,5})|((:[0-9A-Fa-f]{1,4}){0,3}:((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])(\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])){3}))|:))|(([0-9A-Fa-f]{1,4}:){1}(((:[0-9A-Fa-f]{1,4}){1,6})|((:[0-9A-Fa-f]{1,4}){0,4}:((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])(\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])){3}))|:))|(:(((:[0-9A-Fa-f]{1,4}){1,7})|((:[0-9A-Fa-f]{1,4}){0,5}:((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])(\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])){3}))|:)))(%.+)?\s*$"
+
+# Main logic
+if [[ "$ADDR" =~ $ip4regex ]]; then
+ /usr/bin/traceroute ${@:2} $ADDR
+elif [[ "$ADDR" =~ $ip6regex ]]; then
+ /usr/bin/traceroute6 ${@:2} $ADDR
+else
+ echo "Resolving Address: $ADDR"
+ if host $ADDR | awk {' print $4 '} \
+ | grep -m1 -E "$ip4regex">/dev/null; then
+ # resolve address and check if it is ipv4 or other
+ /usr/bin/traceroute ${@:2} $ADDR
+ elif host $ADDR | awk {' print $4 '} \
+ | grep -m1 -E "$ip6regex">/dev/null; then
+ # if ipv6 resolution then ping6
+ /usr/bin/traceroute6 ${@:2} $ADDR
+ else
+ echo -e "\n Unknown address: [$ADDR]\n"
+ fi
+fi
+