title: Get country location of an IP with native PHP
body: <p>Read on before you say this is a duplicate, it's not. (as far as I could see)</p>
  
  <p>I want to get the county code in php from the client.</p>
  
  <p>Yes I know you can do this using external sites or with the likes of "geoip_record_by_name" but I don't want to be dependent on an external site, and I can't install "pear" for php as im using shard Dreamhost hosting.</p>
  
  <p>I thought I could just do something like this:</p>
  
  <pre><code>$output = shell_exec('whois '.$ip.' -H | grep country | awk \'{print $2}\'');
  echo "&lt;pre&gt;$output&lt;/pre&gt;";
  </code></pre>
  
  <p>But dreamhost seems to have an old version of whois (4.7.5), so I get this error on allot of IPs:</p>
  
  <pre><code>Unknown AS number or IP network. Please upgrade this program.
  </code></pre>
  
  <p>So unless someone knows how to get a binary of a newer version of whois onto dreamhost im stuck.</p>
  
  <p>Or is there another way I could get the country code from the client who is loading the page?</p>