Don't use globals when context is available

Also replace deprecated wfGetIP function

Change-Id: I5af1304cb033680a8f1e26ad676f74d12062fe2a