請問php怎麼使用自己構造的IP包頭

來源:互聯網
上載者:User
請教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 應該在下一層
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.