时间:2021-07-01 10:21:17 帮助过:19人阅读
1,'usec'=>500000); // socket_set_option($socket,IPPROTO_IP,IP_HDRINCL,SO_RCVTIMEO,$timeout); socket_set_option($socket,SOL_SOCKET,SO_RCVTIMEO,$timeout); // while(1) socket_sendto($socket, $buf, strlen($buf), 0, $host, $port); } function udpchecksum($ip_src,$ip_dst,$ip_proto,$udp_length,$udp_srcport,$udp_dstport,$dns) { $data = $ip_src . $ip_dst . "\x00" . $ip_proto . $udp_length . $udp_srcport . $udp_dstport . $udp_length . "\x00\x00" . $dns; if (strlen($data)%2) $data .= "\x00"; $bit = unpack('n*', $data); $sum = array_sum($bit); while ($sum >> 16) $sum = ($sum >> 16) + ($sum & 0xffff); return pack('n*', ~$sum); } function ipchecksum($ip_version,$ip_hdr_len,$ip_dsfield,$ip_len,$ip_id,$ip_flags,$ip_frag_offset,$ip_ttl,$ip_proto,$ip_src,$ip_dst) { $data = $ip_version . $ip_hdr_len . $ip_dsfield . $ip_len . $ip_id . $ip_flags . $ip_frag_offset . $ip_ttl . $ip_proto . "\x00\x00" . $ip_src . $ip_dst; $bit = unpack('n*', $data); $sum = array_sum($bit); while ($sum >> 16) $sum = ($sum >> 16) + ($sum & 0xffff); return pack('n*', ~$sum); } function ipto16($ip) { $tmp = explode(".",$ip); $ip = ""; foreach($tmp as $a => $b) { $tmp = dechex($b); if (strlen($tmp)==1) $tmp = "0" . $tmp; $ip .= $tmp; } $ip = pack("h*",$ip); return $ip; } send("8.8.4.4",53,$buf,$dns_flags);