avoid executing code in utils.localinterfaces at import time

moves away from global constants to utility functions.

The code is still only executed once,
but instead of at import time, it is executed at first request.
Merge pull request #4166 from minrk/localinterfaces

avoid executing code in utils.localinterfaces at import time