1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
| <? function gethostbyaddr_timeout($ip, $dns, $timeout=1000) { $data = rand(0, 99); $data = substr($data, 0, 2); $data .= "\1\0\0\1\0\0\0\0\0\0"; $bits = explode(".", $ip); if (count($bits) != 4) return "ERROR"; for ($x=3; $x>=0; $x--) { switch (strlen($bits[$x])) { case 1: $data .= "\1"; break; case 2: $data .= "\2"; break; case 3: $data .= "\3"; break; default: return "INVALID"; } $data .= $bits[$x]; } $data .= "\7in-addr\4arpa\0\0\x0C\0\1"; $handle = @fsockopen("udp://$dns", 53); $requestsize=@fwrite($handle, $data);
@socket_set_timeout($handle, $timeout - $timeout%1000, $timeout%1000); $response = @fread($handle, 1000); @fclose($handle); if ($response == "") return $ip; $type = @unpack("s", substr($response, $requestsize 2)); if ($type[1] == 0x0C00) { $host=""; $len = 0; $position=$requestsize 12; do { $len = unpack("c", substr($response, $position)); if ($len[1] == 0) return substr($host, 0, strlen($host) -1); $host .= substr($response, $position 1, $len[1]) . "."; $position = $len[1] 1; } while ($len != 0); return $ip; } return $ip; } ?>
|