Doesn't accommodate IPv6 gateways, from /var/vcap/sys/log/gateway/gateway.out.log:
Could not resolve hostname 2601:0646:0100:69f5:020d:b9ff:fe48:9249
I think these lines assume IPv4.
I'm not sure that looking up the IP address is necessary—is this a case of over-engineering getting in the way?