You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

79 lines
1.7 KiB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
  1. <?php
  2. function get_substring($string, $start, $end){
  3. $string = ' ' . $string;
  4. $ini = strpos($string, $start);
  5. if ($ini == 0) return '';
  6. $ini += strlen($start);
  7. $len = strpos($string, $end, $ini) - $ini;
  8. return substr($string, $ini, $len);
  9. }
  10. function ip2geo ($host) {
  11. @$data = file_get_contents('http://ipinfo.io/'.$host);
  12. if ($data) {
  13. $data = json_decode($data);
  14. return $data->loc;
  15. } else {
  16. return "";
  17. }
  18. }
  19. function get_client_ip() {
  20. $ipaddress = '';
  21. if (getenv('HTTP_CLIENT_IP'))
  22. $ipaddress = getenv('HTTP_CLIENT_IP');
  23. else if(getenv('HTTP_X_FORWARDED_FOR'))
  24. $ipaddress = getenv('HTTP_X_FORWARDED_FOR');
  25. else if(getenv('HTTP_X_FORWARDED'))
  26. $ipaddress = getenv('HTTP_X_FORWARDED');
  27. else if(getenv('HTTP_FORWARDED_FOR'))
  28. $ipaddress = getenv('HTTP_FORWARDED_FOR');
  29. else if(getenv('HTTP_FORWARDED'))
  30. $ipaddress = getenv('HTTP_FORWARDED');
  31. else if(getenv('REMOTE_ADDR'))
  32. $ipaddress = getenv('REMOTE_ADDR');
  33. else
  34. $ipaddress = 'UNKNOWN';
  35. return $ipaddress;
  36. }
  37. $data = array("points" => array());
  38. $traceroute = "";
  39. function traceroute() {
  40. global $data, $traceroute;
  41. $traceroute = shell_exec("traceroute google.com");
  42. //$traceroute = shell_exec("traceroute " . get_client_ip());
  43. $first = true;
  44. foreach(preg_split("/((\r?\n)|(\r\n?))/", $traceroute) as $line){
  45. if ($first) {
  46. $first = false;
  47. continue;
  48. }
  49. $ipgeo = explode(",", ip2geo(get_substring($line, "(", ")")));
  50. $coordinates = array('x' => $ipgeo[0], 'y' => $ipgeo[1]);
  51. array_push($data['points'], $coordinates);
  52. }
  53. }
  54. function raw_output() {
  55. global $traceroute;
  56. echo json_encode(str_replace("\n", "<br>", $traceroute));
  57. }
  58. function json_output() {
  59. global $data;
  60. echo json_encode($data);
  61. }
  62. ?>