usbip: fix default snippetIpAddress command
This fixes some bugs that I discovered in the default command.
The nix string escaping was wrong so the \ got lost and when I tested this the command had a trailing space that made it fail still.
Also this didn't work when I was using network-mode mirrored since it includes metric in the output:
$ ip route list
default via 192.168.1.1 dev eth0 proto kernel metric 35
192.168.1.0/24 dev eth0 proto kernel scope link metric 291
192.168.1.1 dev eth0 proto kernel scope link metric 35
This also adds a target so you can batch restart the services. This is handy when having multiple YubiKeys and or switching between VPN. Perhaps there could even be some auto-restart thing. Will have to think about if that is a hack or not.
Seems it is still brittle when connected to VPN with multiple routes or any other case where you have multiple routes. This solves it for me:
"$(ip route list | sed -nE 's/(default)? via (.*) dev .*/\\2/p' | head -n1)";
Networking mode NAT
$ wslinfo --networking-mode
nat
$ ip route list
default via 172.17.176.1 dev eth0 proto kernel
172.17.176.0/20 dev eth0 proto kernel scope link src 172.17.181.191
$ ip route list | sed -nE 's/(default)? via (.*) dev .*/\2/p' | head -n1
172.17.176.1
Networking mode mirrored
$ wslinfo --networking-mode
mirrored
$ ip route list
default via 192.168.1.1 dev eth0 proto kernel metric 35
192.168.1.0/24 dev eth0 proto kernel scope link metric 291
192.168.1.1 dev eth0 proto kernel scope link metric 35
$ ip route list | sed -nE 's/(default)? via (.*) dev .*/\2/p' | head -n1
192.168.1.1
Networking mode mirrored + wslvpnkit
$ wslinfo --networking-mode
mirrored
$ ip route list
default via 192.168.127.1 dev wsltap
<-- SNIP VERY LONG LIST OF ROUTES (all on eth0) -->
$ ip route list | sed -nE 's/(default)? via (.*) dev .*/\2/p' | head -n1
192.168.127.1
Is there any reason not to always grab the default route?