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.

58 lines
1.0 KiB

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. $data = array("points" => array());
  20. $traceroute = "";
  21. function traceroute() {
  22. global $data, $traceroute;
  23. $traceroute = shell_exec("traceroute google.com");
  24. $first = true;
  25. foreach(preg_split("/((\r?\n)|(\r\n?))/", $traceroute) as $line){
  26. if ($first) {
  27. $first = false;
  28. continue;
  29. }
  30. $ipgeo = explode(",", ip2geo(get_substring($line, "(", ")")));
  31. $coordinates = array('x' => $ipgeo[0], 'y' => $ipgeo[1]);
  32. array_push($data['points'], $coordinates);
  33. }
  34. }
  35. function raw_output() {
  36. global $traceroute;
  37. echo json_encode($traceroute);
  38. }
  39. function json_output() {
  40. global $data;
  41. echo json_encode($data);
  42. }
  43. ?>