Dotfiles/site-modules/core/files/bin/knock

34 lines
694 B
Text
Raw Normal View History

#!/usr/bin/env bash
#
# Sends a http request to a URL and a port. This is used to knock on port to
# open other ports. See: https://wiki.archlinux.org/index.php/Port_knocking
#
# Using this in your `.ssh/config` as a proxy command can be a nice way to
# automatically knock on ports before connecting with ssh.
#
# Example:
#
# ```
# ProxyCommand bash -c '/home/ade/.dotfiles/bin/knock %h {port_number}; exec /bin/nc %h %p'
# ```
#
# Author: Ade Attwood <code@adeattwood.co.uk>
# Created: 2019-07-11
#
#
# Set off the http request
#
curl --max-time 5 http://$1:$2 > /dev/null 2>&1 &
#
# Wait for a fuw seconds
#
sleep 2.5
#
# Return a success code to carry on the ssh connection
#
exit 0;