I have something similar--for deciding whether to try to connect locally or via remote address:
Match host 10400 exec "timeout 1 nc -z 192.168.1.101 22 2>/dev/null"
Hostname 192.168.1.101
Port 22
Host 10400
Hostname myhost.duckdns.org
Port 564