PHP头条
热点:

请问php怎么使用自己构造的IP包头


请教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 应该在下一层

www.phpzy.comtrue/phprm/54518.htmlTechArticle请问php怎么使用自己构造的IP包头 请教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,...

相关文章

PHP之友评论

今天推荐