欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

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

程序员文章站 2022-06-13 15:34:24
...
请教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 应该在下一层
请问php怎么使用自己构造的IP包头

声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。

相关文章

相关视频