Page Menu
Home
DevCentral
Search
Configure Global Search
Log In
Files
F11722939
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/utils/query-ndp-for-ipv6-neighbor.sh b/utils/query-ndp-for-ipv6-neighbor.sh
new file mode 100644
index 0000000..17f5e0f
--- /dev/null
+++ b/utils/query-ndp-for-ipv6-neighbor.sh
@@ -0,0 +1,66 @@
+#!/bin/sh
+# shellcheck disable=SC2086
+
+# -------------------------------------------------------------
+# rOPS — determine IPv6 router with neighbor discovery protocol
+# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+# Project: Nasqueron
+# Description: Read the output of `ndp -an` to find the first
+# IP address not matching one of the server MAC.
+# That should be a de facto gateway.
+# -------------------------------------------------------------
+
+set -e
+
+# -------------------------------------------------------------
+# Parse arguments
+# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+
+if [ -z "$1" ]; then
+ echo "Usage: $0 <interface>"
+ echo "Example: $0 igb0"
+ exit 1
+fi
+
+IFACE="$1"
+
+# -------------------------------------------------------------
+# Collect local MAC addresses
+# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+
+LOCAL_MACS=$(ifconfig "$IFACE" | while read -r line; do
+ case "$line" in
+ *ether*) set -- $line; echo "$2";;
+ esac
+done)
+
+LOCAL_MACS_STR=""
+for m in $LOCAL_MACS; do
+ LOCAL_MACS_STR="$LOCAL_MACS_STR $m"
+done
+
+# -------------------------------------------------------------
+# Parse ndp -an output
+# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+
+skip=1
+ndp -an | while read -r ipv mac rest; do
+ # Skip header or incomplete entrie
+ if [ $skip -eq 1 ]; then skip=0; continue; fi
+ [ "$mac" = "(incomplete)" ] && continue
+
+ # Skip local MACs
+ found=0
+ for m in $LOCAL_MACS_STR; do
+ [ "$mac" = "$m" ] && found=1 && break
+ done
+ [ $found -eq 1 ] && continue
+
+ # We've got a winner!
+ case "$ipv" in
+ *%*) ipv=${ipv%%%*} ;;
+ esac
+
+ echo "$ipv"
+ break
+done
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Thu, Sep 18, 06:46 (16 h, 58 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2989530
Default Alt Text
(2 KB)
Attached To
Mode
rOPS Nasqueron Operations
Attached
Detach File
Event Timeline
Log In to Comment