diff options
| author | root | 2015-04-01 23:53:58 +0200 |
|---|---|---|
| committer | root | 2015-04-01 23:53:58 +0200 |
| commit | a31396fb8c67f27a0055e4c4a6fa95e3cde24d1a (patch) | |
| tree | 8e5f72013ffe1fda6ab64514a79943f83d841e51 /ip/index.php | |
| parent | 6ec371bff3d3eda0c535fe773c292f66bd746a7a (diff) | |
| download | tools.iamfabulous.de-a31396fb8c67f27a0055e4c4a6fa95e3cde24d1a.tar.gz | |
Small improvements.
Diffstat (limited to 'ip/index.php')
| -rw-r--r-- | ip/index.php | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/ip/index.php b/ip/index.php new file mode 100644 index 0000000..a390ec2 --- /dev/null +++ b/ip/index.php @@ -0,0 +1,60 @@ +<?php + +if ( strpos($_SERVER['HTTP_USER_AGENT'], 'curl') !== false ){ + if ( empty($_GET) ){ + echo $_SERVER["REMOTE_ADDR"]; + exit; + } +} + +if ( empty($_GET) ){ + header($_SERVER["SERVER_PROTOCOL"] . " 302 Moved"); + header("Location: http://".$_SERVER["HTTP_HOST"].str_replace("/index.php", "", $_SERVER["PHP_SELF"] )."/?ip=".$_SERVER["REMOTE_ADDR"]."&geoip=1&header=1&output=html"); + exit; +} + +if ( ! isset($_GET["ip"]) || $_GET["ip"] == "" ){ + $ip = $_SERVER["REMOTE_ADDR"]; +} else { + if( preg_match("/([0-9]+\.){3}[0-9]+/", $_GET["ip"]) ){ + $ip = $_GET["ip"]; + } else { + $ip = gethostbyname($_GET["ip"]); + } +} + +require 'ifconfig.php'; + +$if = new Ifconfig($ip); + +$result = array("ip" => $ip, "hostname" => $if->getReverseDNS()); + +if( isset($_GET["geoip"]) && $_GET["geoip"] != 0){ + $geoip = $result = array_merge($result, $if->getAllGeoipRecords()); +} + +if( isset($_GET["header"]) && $_GET["header"] != 0){ + $header = $if->getHeader(); + $result = array_merge($result, $header); +} + +if( ! isset($_GET["output"]) || $_GET["output"] == "" ){ + $_GET["output"] = "html"; +} + +switch($_GET["output"]){ + case("json"): + header("Content-Type: application/json"); + echo $if->encodeJson($result); + break; + case("html"): + require 'template.php'; + break; + case("php"): + header("Content-Type: text/plain"); + echo serialize($result); + break; + default: + require 'template.php'; + break; +} |
