=5.2 is sure). * - (to verify) Apache >=2.2, using environmental variables. * * Optional: * - pecl-geoip package (on GNU/Linux), to get DB of GeoIPRegion and * GeoIPCountry based on the REMOTE_ADDR (still looking for a less * dependancies solution). * Then after, you have to integrate to your system the databases for * GeoIPCountry and GeoIPRegion (last one not free), but not mandatory. * Tip: you can use the following code to see the available db: * $infos = geoip_db_get_all_info(); * if (is_array($infos)) * var_dump($infos); * * Enjoy. :-) */ $begin = microtime(TRUE); define("ACCESS_TO_SERVER_TIMEZONE", true); define("STUN_SERVER", "stun.services.mozilla.com"); /* * Special feature: allow to download the source code of this file, * as it is on the server. * To use this, add "(?)source" to the URL. */ if (isset($_GET['source'])) { /* Force the web browser to save the file as Text Document instead * of just reading it. */ if (is_file(__FILE__)) { $file = fopen(__FILE__, "rt"); if ($file) { $code = fread($file, filesize(__FILE__)); fclose($file); /* I think too many people forget this! */ /* Same as "$code = file_get_contents(__FILE__);" but I don't use it * because it is too much PHP only. */ header("Content-Type: text/plain; charset=UTF-8"); echo $code; /* Kind of ugly, isn't it? (I am not a PHP developer, * so for me every PHP code is ugly.) */ exit(0); } } header("Status: 500 Internal Server Error", false, 500); header("Content-Type: text/plain; charset=UTF-8"); echo "Error: The file is unreachable."; exit(0); } $type_IP = strstr(getenv('REMOTE_ADDR'), ".") ? "IPv4" : "IPv6"; /* Determine the time used to query the hostname. */ $begin_query_hostname = microtime(TRUE); if (isset($_GET['resolv']) && $_GET['resolv'] == "no") { // Little hack to not waste time like on IPv6 reverse queries $hostname = getenv('REMOTE_ADDR'); } else { $hostname = gethostbyaddr(getenv('REMOTE_ADDR')); } $end_query_hostname = microtime(TRUE); if (isset($_GET['country_code'])) { /* I allow this only for testing purpose, this page is not * designed to do this job in fact (kind of an easter egg). */ $location = array("country_code" => $_GET['country_code'], "region" => (isset($_GET['region']) ? $_GET['region'] : "")); } /* * With RFC1918 IP address (private IP address, like 127.0.0.1), we try to * rely on the timezone system, based on the file /etc/timezone. */ else if (ACCESS_TO_SERVER_TIMEZONE && ( getenv('REMOTE_ADDR') == "127.0.0.1" || getenv('REMOTE_ADDR') == "::1")) { $location = false; /* try to read the file /etc/timezone */ if (is_file("/etc/timezone")) { $timezone_file = fopen("/etc/timezone", "rt"); if ($timezone_file) { $query_timezone = preg_replace('/\r?\n$/', '', fgets($timezone_file)); fclose($timezone_file); } } } /* Test if the required DataBases are available (see Required section). */ else if (function_exists("geoip_db_avail") && function_exists("geoip_region_by_name") && geoip_db_avail(GEOIP_COUNTRY_EDITION) === true && geoip_db_avail(GEOIP_REGION_EDITION_REV0) === true) { $location = geoip_region_by_name(getenv('REMOTE_ADDR')); } else if (function_exists("geoip_db_avail") && function_exists("geoip_country_code_by_name") && geoip_db_avail(GEOIP_COUNTRY_EDITION) === true) { $location = array( "country_code" => geoip_country_code_by_name(getenv('REMOTE_ADDR')), "region" => ""); } else { $location = false; $query_timezone = false; } if (function_exists("geoip_time_zone_by_country_and_region") && isset($location) && $location !== false && is_array($location) && isset($location["country_code"]) && $location["country_code"] != "") { $query_timezone = geoip_time_zone_by_country_and_region( $location["country_code"], $location["region"]); } $timezone = (isset($query_timezone) && $query_timezone !== false) ? $query_timezone : "UTC"; date_default_timezone_set($timezone); /* Detection of User-Agent; if using one of the following User-Agent, * switching in mode = text unless if a mode is already set. * Current User-Agents supported: curl, Wget. */ $mode = (isset($_GET['mode'])) ? $_GET['mode'] : (preg_match('/^(curl|Wget)\//', getenv('HTTP_USER_AGENT')) ? "text" : ""); /* feature: the JSON and TextOnly output formats. */ if ($mode == "text") { $text_display = ""; $text_display .= "IP Address: ".getenv('REMOTE_ADDR'). " (".$type_IP.")\n"; $text_display .= "From IP Port: ".getenv('REMOTE_PORT')."\n"; $text_display .= "HostName: ".$hostname."\n"; $text_display .= "HTTP/2.0: ".((getenv('HTTP2') !== false) ? getenv('HTTP2') : "off")."\n"; $text_display .= "HTTPS connection: "; if (getenv('HTTPS') !== false) { if (getenv('SSL_PROTOCOL') !== false && getenv('SSL_CIPHER') !== false) { $extra_cipher_infos = " [protocol: ".getenv('SSL_PROTOCOL').", cipher: ".getenv('SSL_CIPHER')."]"; } else if (getenv('SSL_PROTOCOL') !== false) { $extra_cipher_infos = " [protocol: ".getenv('SSL_PROTOCOL')."]"; } else if (getenv('SSL_CIPHER') !== false) { $extra_cipher_infos = " [cipher: ".getenv('SSL_CIPHER')."]"; } else { $extra_cipher_infos = ""; } $text_display .= getenv('HTTPS').$extra_cipher_infos."\n"; } else { $text_display .= "off\n"; } $text_display .= "User-Agent: ".getenv('HTTP_USER_AGENT')."\n"; $text_display .= "Date: ".date(DATE_RFC3339)." ".$timezone."\n"; header("Content-Type: text/plain; charset=UTF-8"); echo $text_display; exit(0); } elseif ($mode == "api") { /* @TODO: rework the array to add informations of SSL_CIPHER. */ $json_array = array("type_IP" => $type_IP, "address_IP" => getenv('REMOTE_ADDR'), "port_IP" => getenv('REMOTE_PORT'), "hostname" => $hostname, "http2" => (getenv('HTTP2') !== false) ? getenv('HTTP2') : "off", "https" => (getenv('HTTPS') !== false) ? getenv('HTTPS') : "off", "ua" => getenv('HTTP_USER_AGENT'), "date" => date(DATE_RFC3339)); $json_encoded = json_encode($json_array, JSON_UNESCAPED_UNICODE); if ($json_encoded !== false) { header("Content-Type: application/json; charset=UTF-8"); echo $json_encoded; } else { header("Status: 204 No Content", true, 204); } exit(0); } ?> My IP address: <?php echo getenv('REMOTE_ADDR'); ?> | thican.net
IP Address:
From IP Port:
Is using HTTP/2.0?
Is using a HTTPS connection? [protocol: ".getenv('SSL_PROTOCOL').", cipher: ".getenv('SSL_CIPHER')."]"; } else if (getenv('SSL_PROTOCOL') !== false) { $extra_cipher_infos = "
[protocol: ".getenv('SSL_PROTOCOL')."]"; } else if (getenv('SSL_CIPHER') !== false) { $extra_cipher_infos = "
[cipher: ".getenv('SSL_CIPHER')."]"; } else { $extra_cipher_infos = ""; } if (getenv('HTTPS') == "on") { ?>on ๐Ÿ”’off ๐Ÿ”“
()
The WebRTC function is unavailable in your webbrowser.
Who gives a shโ€ฆ cares this page was generated in second(s) (with second(s) used for the hostname query)? I do.
Different output formats: mode=api" title="JSON">JSON | mode=text" title="Text">Text
Do you want to see how it works?