|
|
- <?php
-
- function get_substring($string, $start, $end){
- $string = ' ' . $string;
- $ini = strpos($string, $start);
- if ($ini == 0) return '';
- $ini += strlen($start);
- $len = strpos($string, $end, $ini) - $ini;
- return substr($string, $ini, $len);
- }
-
- function ip2geo ($host) {
- @$data = file_get_contents('http://ipinfo.io/'.$host);
- if ($data) {
- $data = json_decode($data);
- return $data->loc;
- } else {
- return "";
-
- }
- }
-
- function get_client_ip() {
- $ipaddress = '';
- if (getenv('HTTP_CLIENT_IP'))
- $ipaddress = getenv('HTTP_CLIENT_IP');
- else if(getenv('HTTP_X_FORWARDED_FOR'))
- $ipaddress = getenv('HTTP_X_FORWARDED_FOR');
- else if(getenv('HTTP_X_FORWARDED'))
- $ipaddress = getenv('HTTP_X_FORWARDED');
- else if(getenv('HTTP_FORWARDED_FOR'))
- $ipaddress = getenv('HTTP_FORWARDED_FOR');
- else if(getenv('HTTP_FORWARDED'))
- $ipaddress = getenv('HTTP_FORWARDED');
- else if(getenv('REMOTE_ADDR'))
- $ipaddress = getenv('REMOTE_ADDR');
- else
- $ipaddress = 'UNKNOWN';
- return $ipaddress;
-
- }
-
- $data = array("points" => array());
- $traceroute = "";
-
- function traceroute() {
- global $data, $traceroute;
- $traceroute = shell_exec("traceroute google.com");
- //$traceroute = shell_exec("traceroute " . get_client_ip());
-
- $first = true;
- foreach(preg_split("/((\r?\n)|(\r\n?))/", $traceroute) as $line){
- if ($first) {
- $first = false;
- continue;
- }
- $ipgeo = explode(",", ip2geo(get_substring($line, "(", ")")));
-
- $coordinates = array('x' => $ipgeo[0], 'y' => $ipgeo[1]);
-
- array_push($data['points'], $coordinates);
- }
- }
-
- function raw_output() {
- global $traceroute;
- echo json_encode(str_replace("\n", "<br>", $traceroute));
- }
-
- function json_output() {
- global $data;
- echo json_encode($data);
- }
-
-
-
-
-
- ?>
|