Reputation: 13
I am having trouble sending custom UDP packets with Scapy on Python3 with a MacBook.
want to send a UDP packet with a custom Source IP of 192.168.1.11
to my current machine with the IP of, 192.168.1.17
that is hosting a UDP
Server on port 6789
. I want to send a message saying "Hi" using Scapy so I wrote the following code,
from scapy.all import *
from random import randrange
sendp(IP(src="192.168.11",dst="192.168.1.17")/UDP(sport=randrange(80,65535),dport=6789)/"Hi",iface="en0",count=10)
Then I have a server waiting to respond once data is received and print the message received to the screen. But when executing this code with elevated privileges, scapy says
the packets were sent but the server didn't receive the response.
So I went to en0
the wireless interface on my Mac to debug. This is what I found:
Wireshark says
the source is Applicon_11:f8:61, the destination is 45:00:00:1e:00:01, the protocol is 0xc0a8(Unknown) and the data is 16 bytes of Hex: 0000 45 00 00 1e 00 01 00 00 40 11 f8 61 c0 a8 00 0b ASCII Dump: E.......@.øaÀ¨..
0010 c0 a8 01 11 67 18 1a 85 00 0a b3 66 48 69 À¨..g.....³fHi
I have no idea what any of that means or what I am doing wrong here can anyone help to point me in the right direction?
Upvotes: 0
Views: 8328
Reputation: 5411
sendp
is for sending at layer 2
send
is for sending at layer 3
In your case, you should either use
at layer 2: sendp(Ether()/IP(..)....)
. (Replace Ether
by Loopback
if needed)
at layer 3: send(IP(...))
Upvotes: 2