BioTorrents.de’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.5KB

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