IP Address Resolution'; $page_parent = 'Tools'; $page_current = 'IP Address Resolution'; include('../../config.php'); include('../../header.php'); define('_ERROR_NO_RELEVANT_FIELDS_', '~~~NORELEVANTFIELDS~~~'); function lookupByHostname($item) { $status = ''; $status->buffer = ''; $status->error = ''; exec('nslookup ' . escapeshellcmd($item), $output); $preparse = implode($output); if (eregi('server can\'t find', $preparse)) { $errorMessage = 'nslookup() failure for ' . $item . '.'; $status->error = $errorMessage; return($status); } $sp = split('name = ', $output[4]); /* find real domain this ip belongs to. */ $status->buffer = @substr($sp[1], 0, strlen($sp[1]) -1); /* remove extraneous '.' at end of line. */ return($status); } function parseWhois($item) { $status = ''; $status->buffer = ''; $status->error = ''; $foundMatchingFields = FALSE; if (strlen($item) < 8) { $errorMessage = 'IP Address too short or invalid.'; $status->error = $errorMessage; return ($status); } exec('whois -a ' . escapeshellcmd($item), $output); $preparse = implode($output); if (eregi('No match', $preparse)) { $errorMessage = 'No match indicated in initial WHOIS for ' . $item . '.'; $status->error = $errorMessage; return($status); } else { $i = (int) 0; foreach ($output as $line) { if (eregi('country:', $line)) { $sp = split(':', $line, 2); $status->buffer .= ' ' . @trim($sp[1]); } else if (eregi('Network:name;I:', $line)) { $sp = split(':', $line, 3); $status->buffer .= '; ' . @trim($sp[2]); $foundMatchingFields = TRUE; } else if (eregi('Network:address:', $line)) { $sp = split(':', $line, 3); $status->buffer .= '; ' . @trim($sp[2]); $foundMatchingFields = TRUE; } else if (eregi('Network:Address-1;I:', $line)) { $sp = split(':', $line, 3); $status->buffer .= '; ' . @trim($sp[2]); $foundMatchingFields = TRUE; } else if (eregi('Network:Address-2;I:', $line)) { $sp = split(':', $line, 3); $status->buffer .= '; ' . @trim($sp[2]); $foundMatchingFields = TRUE; } else if (eregi('Network:Address-3;I:', $line)) { $sp = split(':', $line, 3); $status->buffer .= '; ' . @trim($sp[2]); $foundMatchingFields = TRUE; } else if (eregi('Network:street-address:', $line)) { $sp = split(':', $line, 3); $status->buffer .= '; ' . @trim($sp[2]); $foundMatchingFields = TRUE; } else if (eregi('OrgName:', $line)) { $sp = split(':', $line, 3); $status->buffer .= '; ' . @trim($sp[1]); $foundMatchingFields = TRUE; } else if (eregi('network:Org-Name:', $line)) { $sp = split(':', $line, 3); $status->buffer .= '; ' . @trim($sp[2]); $foundMatchingFields = TRUE; } else if (eregi('address:', $line)) { $sp = split(':', $line, 2); $status->buffer .= '; ' . @trim($sp[1]); $foundMatchingFields = TRUE; } else if (eregi('Address:', $line)) { $sp = split(':', $line, 2); $status->buffer .= '; ' . @trim($sp[1]); $foundMatchingFields = TRUE; } else if (eregi('City:', $line)) { $sp = split('City:', $line, 2); $status->buffer .= '; ' . @trim($sp[1]); $foundMatchingFields = TRUE; } else if (eregi('StateProv:', $line)) { $sp = split('StateProv:', $line, 2); $status->buffer .= '; ' . @trim($sp[1]); $foundMatchingFields = TRUE; } else if (eregi('PostalCode:', $line)) { $sp = split('PostalCode:', $line, 2); $status->buffer .= '; ' . @trim($sp[1]); $foundMatchingFields = TRUE; } else if (eregi('Country:', $line)) { $sp = split(':', $line, 2); $status->buffer .= '; ' . @trim($sp[1]); $foundMatchingFields = TRUE; } } } // after iterating through all the WHOIS data we did not find any fields with info, then we found nada if ($foundMatchingFields == FALSE) $status->error = 'We found nada!'; return $status; } function parseItem($item) { $status = ''; $status->error = ''; $status->buffer = ''; $newStatus = ''; $newStatus->error = ''; $newStatus->buffer = ''; $status = parseWhois($item); if (strlen($status->error) > 0) { return $status; } else { $possibleHostname = $status->buffer; $newStatus = parseWhois(escapeshellcmd($possibleHostname)); // Once again to the batcave, err.. Whois, with our new hostname. if (strlen($newStatus->buffer) > 0) $status->buffer = 'Resolves to ' . $newStatus->buffer . '.' . "\n"; } return($status); } function isValidIP($cidr) { $status = TRUE; // Checks for a valid IP address or optionally a cidr notation range, e.g. 1.2.3.4 or 1.2.3.0/24 if(!eregi("^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}(/[0-9]{1,2}){0,1}$", $cidr)) $status = FALSE; if ( $status == TRUE ) { $parts = explode("/", $cidr); $ip = @$parts[0]; $netmask = @$parts[1]; $octets = explode(".", $ip); foreach ( $octets AS $octet ) { if ($octet > 255) $status = FALSE; if (($netmask != "" ) && ( $netmask > 32 )) $status = FALSE; } } return $status; } $buffer = '

'; $itemResult = ''; $itemResult->buffer = ''; $itemResult->error = ''; $theList = ''; $i = (int) 1; if (isset($_POST['theList'])) { $theList = $_POST['theList']; $items = @explode("\n", $theList); $itemCount = count($items); if ($itemCount > 10) die('I said do not abuse it you knob.'); foreach($items as $item) { $item = trim(escapeshellcmd($item)); if (strlen($item) < 8) { } else if (isValidIP($item) == FALSE) { $buffer .= '[' . trim($item) . '] is not a valid IP' . "
\n"; } else { usleep(500); // don't want to flood the whois server $itemResult = parseItem(escapeshellcmd($item)); if (strlen($itemResult->error) > 0) $buffer .= 'No match found for ' . $item . '.'; else $buffer .= '[' . trim($item) . '] ' . $itemResult->buffer . "
\n"; } $i++; } } ?>

Please do not abuse this unnecessarily, kthxbai.

Lookup Results
(max 10 please)

reset