Oppaitime's version of Gazelle
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

get_host.php 1.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?
  2. if (isset($_SERVER['http_if_modified_since'])) {
  3. header('Status: 304 Not Modified');
  4. die();
  5. }
  6. header('Expires: '.date('D, d-M-Y H:i:s \U\T\C', time() + 3600 * 24 * 120)); //120 days
  7. header('Last-Modified: '.date('D, d-M-Y H:i:s \U\T\C', time()));
  8. if (!check_perms('users_view_ips')) {
  9. die('Access denied.');
  10. }
  11. if (empty($_GET['ip'])) {
  12. die('No IP given.');
  13. }
  14. $IP = $_GET['ip'];
  15. $Delimiter = $IP[strcspn($IP, ':.')];
  16. $OctOrHextets = explode($Delimiter, $IP);
  17. if ($Delimiter == '.' && sizeof($OctOrHextets) == 4) { // IPv4
  18. if ( ($OctOrHextets[0] == 127 || $OctOrHextets[0] == 10)
  19. || ($OctOrHextets[0] == 192 && $OctOrHextets[1] == 168)
  20. || ($OctOrHextets[0] == 172 && ($OctOrHextets[1] >= 16 && $OctOrHextets[1] <= 32))
  21. ) {
  22. die('Invalid IPv4 address.');
  23. }
  24. foreach($OctOrHextets as $Octet) {
  25. if ($Octet > 255 || $Octet < 0) {
  26. die('Invalid IPv4 address.');
  27. }
  28. }
  29. } else if (sizeof($OctOrHextets) <= 8) { // IPv6
  30. foreach($OctOrHextets as $Hextet) {
  31. if (strlen($Hextet) > 4) {
  32. die('Invalid IPv6 address.');
  33. }
  34. }
  35. } else {
  36. die('Invalid IP address.');
  37. }
  38. $Host = Tools::lookup_ip($IP);
  39. if ($Host === '') {
  40. trigger_error('Tools::get_host_by_ajax() command failed with no output, ensure that the host command exists on your system and accepts the argument -W');
  41. } elseif ($Host === false) {
  42. print 'Could not retrieve host.';
  43. } else {
  44. print $Host;
  45. }