that gets the external ip, if by chance it gets your local ip that is just random chance. Well not random but it does that when it doesn't resolve your external ip or something like that.

so $ip won't work