Also allow custom IPs and domains to be looked-up
This commit is contained in:
@@ -1,5 +1,10 @@
|
|||||||
RewriteEngine On
|
RewriteEngine On
|
||||||
RewriteBase /
|
RewriteBase /
|
||||||
|
|
||||||
RewriteCond %{REQUEST_FILENAME} !-f
|
RewriteCond %{REQUEST_FILENAME} !-f
|
||||||
RewriteCond %{REQUEST_FILENAME} !-d
|
RewriteCond %{REQUEST_FILENAME} !-d
|
||||||
RewriteRule ^(.*)$ /index.php?m=$1
|
RewriteRule ^([^/]+)/?$ /index.php?m=$1 [L]
|
||||||
|
|
||||||
|
RewriteCond %{REQUEST_FILENAME} !-f
|
||||||
|
RewriteCond %{REQUEST_FILENAME} !-d
|
||||||
|
RewriteRule ^([^/]+)/([^/]+)/?$ index.php?m=$1&t=$2 [L]
|
||||||
|
|||||||
15
README.md
15
README.md
@@ -4,6 +4,8 @@ A simple PHP script to tell a visitor's IP address and more information. This fi
|
|||||||
|
|
||||||
## Plain return
|
## Plain return
|
||||||
|
|
||||||
|
Example: [/][https://ip.nandus.net]
|
||||||
|
|
||||||
When the script is properly installed, one can visit/curl/wget the website to just receive one's public IP address. This is very useful in combination with other scripts (check out my snap-dyndns packages for example).
|
When the script is properly installed, one can visit/curl/wget the website to just receive one's public IP address. This is very useful in combination with other scripts (check out my snap-dyndns packages for example).
|
||||||
|
|
||||||
```
|
```
|
||||||
@@ -13,6 +15,8 @@ max@laptop ~> wget -qO - ip.nandus.net
|
|||||||
|
|
||||||
## Detailed return
|
## Detailed return
|
||||||
|
|
||||||
|
Example: [/myself](https://ip4.nandus.net/myself)
|
||||||
|
|
||||||
Given the location of the script is `ip.example.com`, you can also receive more information about the HTTP headers or the IP's reverse lookup:
|
Given the location of the script is `ip.example.com`, you can also receive more information about the HTTP headers or the IP's reverse lookup:
|
||||||
|
|
||||||
```
|
```
|
||||||
@@ -30,6 +34,17 @@ HOSTNAME: p5B3E4401.dip0.t-ipconnect.de
|
|||||||
IPv4 REVERSE LOOKUP: 91.62.68.1
|
IPv4 REVERSE LOOKUP: 91.62.68.1
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Additionally you will be given a whois output of your IP.
|
||||||
|
|
||||||
|
## Custom DNS and IP lookup
|
||||||
|
|
||||||
|
Example DNS: [/dns/example.com](https://ip.nandus.net/dns/example.com)
|
||||||
|
Example IP: [/ip/8.8.8.8](https://ip.nandus.net/ip/8.8.8.8)
|
||||||
|
|
||||||
|
You can also freely look up any hostname or IP. For domains, this will return a useful list of different DNS records (A, AAAA, NS, MX, TXT, SOA etc).
|
||||||
|
|
||||||
|
You will also be given a whois output of the domain or IP.
|
||||||
|
|
||||||
## Ideal domain setup
|
## Ideal domain setup
|
||||||
|
|
||||||
In order to use IPv4- and IPv6-only domains, you'll have to have control over the DNS nameserver records of your own domain.
|
In order to use IPv4- and IPv6-only domains, you'll have to have control over the DNS nameserver records of your own domain.
|
||||||
|
|||||||
174
index.php
174
index.php
@@ -2,16 +2,52 @@
|
|||||||
|
|
||||||
$config = include('config.php');
|
$config = include('config.php');
|
||||||
|
|
||||||
|
$m = isset($_GET['m']) ? $_GET['m'] : false;
|
||||||
|
$t = isset($_GET['t']) ? $_GET['t'] : false;
|
||||||
|
|
||||||
// Define method by get parameter
|
// Define method by get parameter
|
||||||
if(empty($_GET)) {
|
if(empty($_GET)) {
|
||||||
$method = "simple";
|
$method = "simple";
|
||||||
|
} elseif($m === "dns" && ! empty($t)) {
|
||||||
|
$method = "dns";
|
||||||
|
} elseif($m === "ip" && ! empty($t)) {
|
||||||
|
$method = "ip";
|
||||||
|
} elseif($m === "myself" && empty($t)) {
|
||||||
|
$method = "myself";
|
||||||
} else {
|
} else {
|
||||||
$method = $_GET['m'];
|
$method = "unknown";
|
||||||
}
|
}
|
||||||
|
|
||||||
if($method === "simple") { // simple
|
if($method === "simple") { // simple
|
||||||
echo $_SERVER['REMOTE_ADDR'] . "\n";
|
$ip = $_SERVER['REMOTE_ADDR'];
|
||||||
} elseif($method === "detailed" ) { // detailed
|
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("REMOTE_ADDR");
|
||||||
readheader("HTTP_X_FORWARDED_FOR");
|
readheader("HTTP_X_FORWARDED_FOR");
|
||||||
readheader("HTTP_USER_AGENT");
|
readheader("HTTP_USER_AGENT");
|
||||||
@@ -21,33 +57,129 @@ if($method === "simple") { // simple
|
|||||||
readheader("HTTP_FORWARDED");
|
readheader("HTTP_FORWARDED");
|
||||||
readheader("HTTP_HOST");
|
readheader("HTTP_HOST");
|
||||||
readheader("HTTP_URI");
|
readheader("HTTP_URI");
|
||||||
$hostname = gethostbyaddr($_SERVER['REMOTE_ADDR']);
|
|
||||||
echo "<br />";
|
echo "<br />";
|
||||||
echo "<strong>HOSTNAME</strong>: " . $hostname;
|
}
|
||||||
echo "<br />";
|
// DNS LOOKUP
|
||||||
echo "<strong>IPv4 REVERSE LOOKUP</strong>: " . implode(', ', gethostbynamel($hostname));
|
function show_hostname($ip) {
|
||||||
echo "<br /><br /><strong>WHOIS:</strong>";
|
global $hostname;
|
||||||
$whois = shell_exec("whois " . $_SERVER['REMOTE_ADDR']);
|
$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 "<pre>"; print_r($whois); echo "</pre>";
|
||||||
echo "<br />";
|
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";
|
||||||
|
}
|
||||||
|
|
||||||
echo "<br /><hr /><br />";
|
// OTHER
|
||||||
echo 'Plain IP address: <a href="//'.$config->ip4domain.'">IPv4</a> | <a href="//'.$config->ip6domain.'">IPv6</a>';
|
$dnsrecords = dnsrecords($hostname, "OTHER");
|
||||||
echo "<br />";
|
if(!empty($dnsrecords)) {
|
||||||
echo 'Detailed header info: <a href="//'.$config->ip4domain.'/'.$config->detailed_uri.'">IPv4</a> | <a href="//'.$config->ip6domain.'/'.$config->detailed_uri.'">IPv6</a>';
|
echo "<strong>Other DNS records</strong>:<br/>\n ";
|
||||||
} else { // wrong URL
|
echo "<pre>"; print_r($dnsrecords); echo "</pre>";
|
||||||
header("HTTP/1.1 301 Moved Permanently");
|
echo "<br />\n";
|
||||||
header("Location:/".$config->detailed_uri."");
|
}
|
||||||
exit;
|
}
|
||||||
|
// 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
|
echo "<strong>" . $value . "</strong>: "; // show desired value
|
||||||
if(isset($_SERVER[$value])) { // only if desired header has been delivered
|
if(isset($_SERVER[$value])) { // only if desired header has been delivered
|
||||||
echo $_SERVER[$value];
|
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