Skip to content

Instantly share code, notes, and snippets.

@iamahuman
Last active February 24, 2017 01:40
Show Gist options
  • Save iamahuman/19d95e0df1cf829d65c035779e0edf99 to your computer and use it in GitHub Desktop.
Save iamahuman/19d95e0df1cf829d65c035779e0edf99 to your computer and use it in GitHub Desktop.
ifconfig wrapper with SSH connection protection
#!/bin/bash
if [ -n "$SSH_CONNECTION" ] && [ "$2" = "down" ]; then
IFS=' ' read -ra conn_info <<< "$SSH_CONNECTION"
if ip address show "$1" | grep -q "${conn_info[2]}"; then
echo "Warning: Current SSH connection is bound on ${conn_info[2]} ($1)" >&2
exit 1
fi
fi
exec /sbin/ifconfig "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment