How can I use a self-constructed IP header in php?-php Tutorial

Source: Internet
Author: User
Ask php how to use the self-constructed IP address header PHPcode & lt ;? Php Data $ dns_id & quot; x80xc1 & quot; $ dns_flags & quot; x01x00 & quot; $ dns_count_queries & quot; x00x01 & quot; $ dns_count_answers & quot; x00x ask php how to use self-constructed IP address headers
PHP code
  
  1, 'usec '=> 500000); // socket_set_option ($ socket, IPPROTO_IP, scheme, 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_ds Tport. $ 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 & 0 xffff); 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 & 0 xffff); 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 );


This is a program for querying the IP address of a specified domain name from a specified dns server. it can be captured using Wireshark for testing. However, it does not use its network layer, that is, the IP header, I want to use a self-constructed IP header,
Set
$ Buf = $ ip_header. $ udp. $ dns;
// $ Buf = $ udp. $ dns;
Change
$ Buf = $ ip_header. $ udp. $ dns;
// $ Buf = $ udp. $ dns;
The result still does not work. it should be a problem with the send function. how can I modify it?

------ Solution --------------------
I don't know what you are doing? The sock package must be used at the user layer.
Encapsulate the ip address at the next layer.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.