Also allow custom IPs and domains to be looked-up
This commit is contained in:
176
index.php
176
index.php
@@ -2,16 +2,52 @@
|
||||
|
||||
$config = include('config.php');
|
||||
|
||||
$m = isset($_GET['m']) ? $_GET['m'] : false;
|
||||
$t = isset($_GET['t']) ? $_GET['t'] : false;
|
||||
|
||||
// Define method by get parameter
|
||||
if(empty($_GET)) {
|
||||
$method = "simple";
|
||||
} elseif($m === "dns" && ! empty($t)) {
|
||||
$method = "dns";
|
||||
} elseif($m === "ip" && ! empty($t)) {
|
||||
$method = "ip";
|
||||
} elseif($m === "myself" && empty($t)) {
|
||||
$method = "myself";
|
||||
} else {
|
||||
$method = $_GET['m'];
|
||||
$method = "unknown";
|
||||
}
|
||||
|
||||
if($method === "simple") { // simple
|
||||
echo $_SERVER['REMOTE_ADDR'] . "\n";
|
||||
} elseif($method === "detailed" ) { // detailed
|
||||
$ip = $_SERVER['REMOTE_ADDR'];
|
||||
echo $ip . "\n";
|
||||
exit;
|
||||
} elseif($method === "myself" ) { // detailed info about own IP
|
||||
$ip = $_SERVER['REMOTE_ADDR'];
|
||||
show_http_headers();
|
||||
show_hostname($ip);
|
||||
show_reverse($hostname);
|
||||
show_whois($ip);
|
||||
} elseif($method === "ip" ) { // detailed info an IP
|
||||
$ip = $t;
|
||||
show_hostname($ip);
|
||||
show_reverse($hostname);
|
||||
show_whois($ip);
|
||||
} elseif($method === "dns" ) { // detailed info a host name
|
||||
$hostname = $t;
|
||||
show_reverse($hostname);
|
||||
show_dnsrecords($hostname);
|
||||
show_whois($hostname);
|
||||
} else if($method === "unknown") { // wrong URL
|
||||
header("HTTP/1.1 301 Moved Permanently");
|
||||
header("Location:/".$config->detailed_uri."");
|
||||
exit;
|
||||
}
|
||||
footer();
|
||||
|
||||
// HTTP HEADERS
|
||||
function show_http_headers() {
|
||||
echo "<h2>YOUR HTTP HEADERS</h2>";
|
||||
readheader("REMOTE_ADDR");
|
||||
readheader("HTTP_X_FORWARDED_FOR");
|
||||
readheader("HTTP_USER_AGENT");
|
||||
@@ -21,33 +57,129 @@ if($method === "simple") { // simple
|
||||
readheader("HTTP_FORWARDED");
|
||||
readheader("HTTP_HOST");
|
||||
readheader("HTTP_URI");
|
||||
$hostname = gethostbyaddr($_SERVER['REMOTE_ADDR']);
|
||||
echo "<br />";
|
||||
echo "<strong>HOSTNAME</strong>: " . $hostname;
|
||||
echo "<br />";
|
||||
echo "<strong>IPv4 REVERSE LOOKUP</strong>: " . implode(', ', gethostbynamel($hostname));
|
||||
echo "<br /><br /><strong>WHOIS:</strong>";
|
||||
$whois = shell_exec("whois " . $_SERVER['REMOTE_ADDR']);
|
||||
}
|
||||
// DNS LOOKUP
|
||||
function show_hostname($ip) {
|
||||
global $hostname;
|
||||
$hostname = ip2hostname($ip);
|
||||
echo "<strong>HOSTNAME</strong>: " . link_target($hostname);
|
||||
echo "<br />\n";
|
||||
}
|
||||
// REVERSE IP4 LOOKUP
|
||||
function show_reverse($hostname) {
|
||||
global $hostname;
|
||||
$ip = hostname2ip($hostname);
|
||||
echo "<strong>IPv4 REVERSE LOOKUP</strong>: " . link_target($ip);
|
||||
echo "<br />\n";
|
||||
}
|
||||
// WHOIS
|
||||
function show_whois($target) {
|
||||
echo "<h2>WHOIS</h2>\n";
|
||||
if(preg_match('/^(?!\-)(?:[a-zA-Z\d\-]{0,62}[a-zA-Z\d]\.){1,126}(?!\d+)[a-zA-Z\d]{1,63}$/', $target)) {
|
||||
// if domain, skip subdomains
|
||||
preg_match('/[a-zA-Z\d]+\.[a-zA-Z\d]+$/', $target, $m);
|
||||
$target = $m[0];
|
||||
}
|
||||
$whois = shell_exec("whois " . $target );
|
||||
echo "<pre>"; print_r($whois); echo "</pre>";
|
||||
echo "<br />";
|
||||
|
||||
echo "<br /><hr /><br />";
|
||||
echo 'Plain IP address: <a href="//'.$config->ip4domain.'">IPv4</a> | <a href="//'.$config->ip6domain.'">IPv6</a>';
|
||||
echo "<br />";
|
||||
echo 'Detailed header info: <a href="//'.$config->ip4domain.'/'.$config->detailed_uri.'">IPv4</a> | <a href="//'.$config->ip6domain.'/'.$config->detailed_uri.'">IPv6</a>';
|
||||
} else { // wrong URL
|
||||
header("HTTP/1.1 301 Moved Permanently");
|
||||
header("Location:/".$config->detailed_uri."");
|
||||
exit;
|
||||
echo "<br />\n";
|
||||
}
|
||||
// DNSRECORDS
|
||||
function show_dnsrecords($hostname) {
|
||||
echo "<h2>DNS Records</h2>\n";
|
||||
// A
|
||||
$dnsrecords = dnsrecords($hostname, "DNS_A");
|
||||
foreach($dnsrecords as $key=>$value) {
|
||||
echo "<strong>" . $value['type'] . "</strong>: ";
|
||||
echo link_target($value['ip']) . "<br />\n";
|
||||
}
|
||||
// AAAA
|
||||
$dnsrecords = dnsrecords($hostname, "DNS_AAAA");
|
||||
foreach($dnsrecords as $key=>$value) {
|
||||
echo "<strong>" . $value['type'] . "</strong>: ";
|
||||
echo link_target($value['ipv6']) . "<br />\n";
|
||||
}
|
||||
// MX
|
||||
$dnsrecords = dnsrecords($hostname, "DNS_MX");
|
||||
foreach($dnsrecords as $key=>$value) {
|
||||
echo "<strong>" . $value['type'] . "</strong>: ";
|
||||
echo link_target($value['target']) . " (" . $value['pri'] . ")<br />\n";
|
||||
}
|
||||
// NS
|
||||
$dnsrecords = dnsrecords($hostname, "DNS_NS");
|
||||
foreach($dnsrecords as $key=>$value) {
|
||||
echo "<strong>" . $value['type'] . "</strong>: ";
|
||||
echo link_target($value['target']) . "<br />\n";
|
||||
}
|
||||
// TXT
|
||||
$dnsrecords = dnsrecords($hostname, "DNS_TXT");
|
||||
foreach($dnsrecords as $key=>$value) {
|
||||
echo "<strong>" . $value['type'] . "</strong>: ";
|
||||
$i = 0;
|
||||
foreach($value['entries'] as $entry) {
|
||||
if($i !== 0){echo " | ";}
|
||||
echo $entry;
|
||||
}
|
||||
echo "<br />\n";
|
||||
}
|
||||
// SOA
|
||||
$dnsrecords = dnsrecords($hostname, "DNS_SOA");
|
||||
foreach($dnsrecords as $key=>$value) {
|
||||
echo "<strong>" . $value['type'] . "</strong>: ";
|
||||
echo "" . $value['mname'] . " (mname), ";
|
||||
echo "" . $value['rname'] . " (rname), ";
|
||||
echo "" . $value['serial'] . " (serial)<br />\n";
|
||||
}
|
||||
|
||||
// OTHER
|
||||
$dnsrecords = dnsrecords($hostname, "OTHER");
|
||||
if(!empty($dnsrecords)) {
|
||||
echo "<strong>Other DNS records</strong>:<br/>\n ";
|
||||
echo "<pre>"; print_r($dnsrecords); echo "</pre>";
|
||||
echo "<br />\n";
|
||||
}
|
||||
}
|
||||
// PRINT FOOTER
|
||||
function footer() {
|
||||
global $config;
|
||||
echo "<br /><hr /><br />\n";
|
||||
echo 'Your plain IP address: <a href="//'.$config->ip4domain.'">IPv4</a> | <a href="//'.$config->ip6domain.'">IPv6</a>';
|
||||
echo "<br />\n";
|
||||
echo 'Your detailed IP info: <a href="//'.$config->ip4domain.'/'.$config->detailed_uri.'">IPv4</a> | <a href="//'.$config->ip6domain.'/'.$config->detailed_uri.'">IPv6</a>';
|
||||
}
|
||||
|
||||
function readheader($value)
|
||||
{
|
||||
// HELPER FUNCTIONS
|
||||
function readheader($value) {
|
||||
echo "<strong>" . $value . "</strong>: "; // show desired value
|
||||
if(isset($_SERVER[$value])) { // only if desired header has been delivered
|
||||
echo $_SERVER[$value];
|
||||
}
|
||||
echo "<br />";
|
||||
echo "<br />\n";
|
||||
}
|
||||
function ip2hostname($ip) {
|
||||
$hostname = gethostbyaddr($ip);
|
||||
return $hostname;
|
||||
}
|
||||
function hostname2ip($hostname) {
|
||||
$ip = implode(', ', gethostbynamel($hostname));
|
||||
return $ip;
|
||||
}
|
||||
function dnsrecords($hostname, $record = "DNS_ALL") {
|
||||
if($record === "OTHER") {
|
||||
$dnsrecords = dns_get_record($hostname, DNS_ALL - DNS_A - DNS_AAAA - DNS_MX - DNS_NS - DNS_TXT - DNS_SOA);
|
||||
} else {
|
||||
$dnsrecords = dns_get_record($hostname, constant($record));
|
||||
}
|
||||
return $dnsrecords;
|
||||
}
|
||||
function link_target($target) {
|
||||
if(filter_var($target, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) || filter_var($target, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) {
|
||||
// target is an IP
|
||||
return "<a href='/ip/" . $target . "/'>" . $target . "</a>";
|
||||
} elseif(preg_match('/^(?!\-)(?:[a-zA-Z\d\-]{0,62}[a-zA-Z\d]\.){1,126}(?!\d+)[a-zA-Z\d]{1,63}$/', $target)) {
|
||||
return "<a href='/dns/" . $target . "/'>" . $target . "</a>";
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
Reference in New Issue
Block a user