Skip to content

Instantly share code, notes, and snippets.

@manesec
Last active January 16, 2025 03:47
Show Gist options
  • Select an option

  • Save manesec/9854551b706b675926350bffd55858ff to your computer and use it in GitHub Desktop.

Select an option

Save manesec/9854551b706b675926350bffd55858ff to your computer and use it in GitHub Desktop.
Use for Ping Monitor
#! /bin/bash
interface="$(ip tuntap show | cut -d : -f1 | head -n 1)"
gatewayip=`ip -j route list table all | jq -r '.[] | select(.dev=="'$interface'") | .gateway' | grep -v null | head -n 1`
localip=`ip -j route list table all | jq -r '.[] | select(.dev=="'$interface'") | .prefsrc' | grep -v null | head -n 1`
delay=`ping $gatewayip -W 1 -c 1| awk -F'/' 'END{ print (/^rtt/? ""$5" ms":"") }'`
if [[ $interface == '' ]]; then
echo "" ;
else
echo "$localip - $delay" ;
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment