Move localhost / loopbackinterface detection to TestUtils

This also fixes #1303 .

@trustin I would prefer this over just logging.