This is much easier with the Net::Frame library. It works fine on Windows / Strawberry (which I gather you're running based on the shebang in your code).

<shameless plug>You can also check out the Perl Packet Crafter (PPC) which provides a scapy (http://www.secdev.org/projects/scapy/)-like interface to the Net::Frame suite.</shameless plug>

POD: http://www.vinsworld.com/software/ppc.html
Direct Download: http://www.vinsworld.com/software/ppc.zip

In your case, your TCP SYN packet is as easy as:

VinsWorldcom@C:\Users\VinsWorldcom\tmp\ppc> ppc -i "Wireless Network C +onnection" Welcome to Perl Packet Crafter (PPC) Version: 1.02 Copyright (C) VinsWorldcom 2012 Wireless Network Connection ppc> $r = srp( packet( ETHER, IPv4(dst=>'www.google.com',id=>'19245',f +lags=>NF_IPv4_DONT_FRAGMENT),TCP(dst=>80,seq=>'13456')) ); Sent => Received ppc> $r->report; Packet 1 Sent: Sat Mar 14 20:03:17 2015 (1426377797.565053) ETH: dst:xx:xx:xx:xx:xx:xx src:xx:xx:xx:xx:xx:xy type:0x0800 IPv4: version:4 hlen:5 tos:0x00 length:40 id:19245 IPv4: flags:0x02 offset:0 ttl:128 protocol:0x06 checksum:0x3092 IPv4: src:192.168.10.105 dst:216.58.219.196 TCP: src:5443 dst:80 seq:0x3490 ack:0x0000 TCP: off:0x05 x2:0x0 flags:0x02 win:65535 checksum:0xe6ae urp:0x0 +0 Recv: Sat Mar 14 20:03:17 2015 (1426377797.591432) ETH: dst:c0:cb:38:08:46:76 src:58:6d:8f:78:ad:40 type:0x0800 IPv4: version:4 hlen:5 tos:0x20 length:44 id:39786 IPv4: flags:0x00 offset:0 ttl:55 protocol:0x06 checksum:0x6931 IPv4: src:216.58.219.196 dst:192.168.10.105 TCP: src:80 dst:5443 seq:0x15f689c0 ack:0x3491 TCP: off:0x06 x2:0x0 flags:0x12 win:42900 checksum:0x87b4 urp:0x0 +0 TCP: optionsLength:4 options:02040596 Interval = 0.026379 secs ppc>

Note the MAC's above have been obscured. And you can specify your source IP and TCP port if you want, although I didn't. Note if you "spoof" your source IP, you won't get the response packet - that should be pretty obvious.


In reply to Re: Perl code to send TCP/IP packet not working by VinsWorldcom
in thread Perl code to send TCP/IP packet not working by iThunder

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.