Better logic for identifying ip address