請教php如何使用自己構造的IP包頭
PHP code
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);
這是個查詢向指定dns伺服器查詢指定網域名稱IP資訊的程式,用Wireshark抓包測試可用,但是現在沒有用自己的網路層,也就是IP頭,我要用自己構造的IP頭,
把
$buf = $ip_header . $udp . $dns;
//$buf = $udp . $dns;
改成
$buf = $ip_header . $udp . $dns;
//$buf = $udp . $dns;
結果還是不行,應該是send那函數的問題,請問下應該怎麼修改
------解決方案--------------------
不知道你在幹什嗎?利用 sock 包的肯定是在使用者層了
封裝 ip 應該在下一層