From 1f8755e7fa091ae705eda151882424d4e95e1832 Mon Sep 17 00:00:00 2001 From: John Southworth Date: Wed, 17 Aug 2011 19:36:11 -0500 Subject: Initial traceroute rework checkin (cherry picked from commit ce64904840bea3e716a7de3eca2618e63bcd87d1) --- scripts/vyatta-traceroute | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 scripts/vyatta-traceroute (limited to 'scripts/vyatta-traceroute') 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 + -- cgit v1.2.3