modifed the code detecting IP address to check for external IP address