Assign variable to function

Assign variable to function

I'm trying to assign IPAddress to using the code below:

  1. function GetIP() {
  2. $.getJSON("http://jsonip.appspot.com?callback=?",function(ipadd){
  3.     //var IPAddr;
  4.     IPAddr = ipadd.ip;
  5.     return IPAddr;
  6.   });
  7.   }
  8.   var IPAddress = GetIP()
What am I doing wrong?  When I alert(IPAddress); I get undefined.  If I alert(IPAddr); within the function, it works just fine.