Skip to content
This repository has been archived by the owner on Sep 24, 2022. It is now read-only.

Commit

Permalink
Implement wishfish, ipv6_address
Browse files Browse the repository at this point in the history
  • Loading branch information
claui committed Jul 28, 2017
1 parent 7b38acb commit e6038b0
Show file tree
Hide file tree
Showing 6 changed files with 165 additions and 0 deletions.
15 changes: 15 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Copyright (c) 2017 Claudia <clau@tiqua.de>

Permission to use, copy, modify, and/or distribute this software for
any purpose with or without fee is hereby granted, provided that the
above copyright notice and this permission notice appear in all
copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
90 changes: 90 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
# Wishfish

**Wishfish** is a SSH wrapper for macOS that binds to a specific network interface, e. g. Wi-Fi.


## Warning

**This is alpha-quality software.** If you don’t know what this means, do not use Wishfish.

If you do use Wishfish, be advised that it is largely untested. That said, it’s only a tiny wrapper so I expect it to work well enough.


## System requirements

To use Wishfish, you need OS&nbsp;X 10.11 El Capitan, macOS 10.12 Sierra, or a later macOS version.


## Purpose

I use this command to force SSH to run over the Wi-Fi interface even if there is another network interface with higher priority (e.&nbsp;g. Ethernet).

In other words, `wishfish` allows you to disconnect an Ethernet cable from your Mac without disconnecting your active SSH sessions as long as you’re on Wi-Fi.

Without `wishfish`, you’d need to either configure your Wi-Fi interface to have the highest priority, which you may not want at all times because your Ethernet is faster; or, you’d need to pass your own link-local IP address to the `ssh` command so it binds to that interface. The latter is especially cumbersome because you may not want to memorize your local IP address, or you may not find it acceptable that the IP address can change.


## Installation

1. Make sure you have [Homebrew](https://brew.sh) installed.

2. Run `brew tap claui/public` if you haven’t already done so.

3. Run:

```
brew install wishfish
```


## Usage

There are two executables in this package: `wishfish` and `ipv6_address`.

### Using wishfish

Run the `wishfish` command from the Terminal to establish a SSH connection. As the first command-line argument, pass the name of the interface you wish to bind, and then append your `ssh` arguments:

```
$ wishfish <interface> <ssh_arguments>
```

For example:

```
$ wishfish en0 -p 22 user@example.com
```


### Using ipv6_address

This package depends on another CLI tool `ipv6_address`, which tells you one of your current IPv6 addresses bound to specific network interface. Pass the interface name as the single command-line argument:

```
$ bin/ipv6_address
```

Running ipv6_address results in one of the following two scenarios:

- `ipv6_address` finds one or more IPv6 addresses currently bound to the given interface. It then prints one of those addresses to standard output, and the exit status will be 0.

- `ipv6_address` does not find an IPv6 address to the given interface, or runs into another error. Either way, it does not print anything on standard output, and exits with a status code of 1.


## License

Copyright (c) 2017 Claudia <clau@tiqua.de>

Permission to use, copy, modify, and/or distribute this software for
any purpose with or without fee is hereby granted, provided that the
above copyright notice and this permission notice appear in all
copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
1 change: 1 addition & 0 deletions bin/ipv6_address
6 changes: 6 additions & 0 deletions bin/wishfish
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash

cd "$(dirname "${BASH_SOURCE[0]}")/.."
. "lib/$(basename "${0}").bash"

_"$(basename "${0}")" "$@"
22 changes: 22 additions & 0 deletions lib/ipv6_address.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
_print_help_text() {
echo >&2 "Usage: $(basename "${0}") <interface>"
echo >&2 "Example: $(basename "${0}") en0"
}

_ipv6_address() {
local interface="${1}"

if [[ ! ${interface} ]]; then
_print_help_text
return 1
fi

ifconfig "${interface}" inet6 \
| awk -e "$(cat << 'EOF'
NR==1 && /UP/ { up = 1 }
NR==1 && !up { exit 1 }
/inet6/ && !done { print $2; done = 1 }
ENDFILE { exit !done }
EOF
)"
}
31 changes: 31 additions & 0 deletions lib/wishfish.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
. 'lib/ipv6_address.bash'

_print_help_text() {
echo >&2 "Usage: $(basename "${0}")" \
"<interface> <ssh_arguments>"
echo >&2 "Example: $(basename "${0}") en0 -p 22 user@example.com"
}

_wishfish() {
local interface ip_address ssh_command

interface="${1}"
shift

if [[ -z "${interface}" || $# -eq 0 ]]; then
_print_help_text
return 1
fi

ip_address="$(_ipv6_address "${interface}" || true)"
if [[ ! "${ip_address}" ]]; then
ip_address="$(ipconfig getifaddr ${interface} || true)"
fi

ssh_command="ssh"
if [[ "${ip_address}" ]]; then
ssh_command="${ssh_command} -b ${ip_address}"
fi

${ssh_command} "$@"
}

0 comments on commit e6038b0

Please sign in to comment.