If your hostnames fit a pattern, you can use SSH's patterns:
You can use patterns in ~/.ssh/config. From man ssh_config:
PATTERNS
A pattern consists of zero or more non-whitespace characters, ‘*’ (a
wildcard that matches zero or more characters), or ‘?’ (a wildcard that
matches exactly one character). For example, to specify a set of
declarations for any host in the “.co.uk” set of domains, the following
pattern could be used:
Host *.co.uk
The following pattern would match any host in the 192.168.0.[0-9] network
range:
Host 192.168.0.?
So, if you want to proxy everything in *.example.com, then in your ~/.ssh/config, put:
Host *.example.com
User user
ProxyCommand ssh server nc %h %p 2> /dev/null
Or, using ssh's own options, you can avoid netcat:
Host *.example.com
User user
ProxyCommand ssh -qW %h:%p server
From man ssh:
-W host:port
Requests that standard input and output on the client be
forwarded to host on port over the secure channel. Implies -N,
-T, ExitOnForwardFailure and ClearAllForwardings.