Added more accurate detection of ip address.