getIP.php 833 B

12345678910111213141516171819202122
  1. <?php
  2. $ip="";
  3. header('Content-Type: text/plain; charset=utf-8');
  4. if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
  5. $ip=$_SERVER['HTTP_CLIENT_IP'];
  6. } elseif (!empty($_SERVER['X-Real-IP'])) {
  7. $ip=$_SERVER['X-Real-IP'];
  8. } elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
  9. $ip=$_SERVER['HTTP_X_FORWARDED_FOR'];
  10. } else {
  11. $ip=$_SERVER['REMOTE_ADDR'];
  12. }
  13. $ip=preg_replace("/^::ffff:/", "", $ip);
  14. $isp="";
  15. if(isset($_GET["isp"])){
  16. $json = file_get_contents("https://ipinfo.io/".$ip."/json");
  17. $details = json_decode($json,true);
  18. if(array_key_exists("org",$details)) $isp.=$details["org"]; else $isp.="Unknown ISP";
  19. if(array_key_exists("country",$details)) $isp.=" (".$details["country"].")";
  20. echo $ip." - ".$isp;
  21. } else echo $ip;
  22. ?>