请问php怎么使用自己构造的IP包头
程序员文章站
2022-06-13 15:34:24
...
请教php如何使用自己构造的IP包头
这是个查询向指定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 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的pdo查询出来怎么会是空白?
-
请问php怎么使用自己构造的IP包头
-
请问使用PHP怎么写出高效率的ping检测
-
请问怎么在PHP多维数组中筛选出自己想要的数值并输出
-
为什么在php的构造函数中无法使用return,如果使用,会怎么样?
-
做php开发也有半年多了,但都是使用的thinkphp框架,总感觉自己的基础不行,该怎么提高?
-
做php开发也有半年多了,但都是使用的thinkphp框架,总感觉自己的基础不行,该怎么提高?
-
为什么在php的构造函数中无法使用return,如果使用,会怎么样?
-
请问大家一般使用php的单元测试吗 如果不 一般怎么科学地测试代码
-
请问怎么使用Php生成真正的Excel文件?PS:不使用PHPEXCEL太卡