improve GetIpAddr and add tests