Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sending packets with Scapy within Python environment

Tags:

python

scapy

I am playing around with Scapy and I want to use it within a Python script but sending packets seem to be a problem. Here is my code.

Scapy Shell:

send(IP(src="10.0.99.100",dst="10.1.99.100")/ICMP()/"Hello World")

This works fine and sends the packet.

Python script:

#! /usr/bin/env python

from scapy.all import sr1,IP,ICMP

p=sr1(IP(src="10.0.99.100",dst="10.1.99.100")/ICMP()/"Hello World")

This runs fine but when it tries to send the packet I get:

WARNING: No route found for IPv6 destination :: (no default route?)
Begin emission:
.Finished to send 1 packets.
....^C
Received 5 packets, got 0 answers, remaining 1 packets
like image 325
Evan Clark Avatar asked Jul 31 '13 13:07

Evan Clark


People also ask

How to send and receive packets with Scapy?

Following are the methods to send and receive packets with scapy module: We can use the send () function to send packets at layer 3. In this case, Scapy will handle the routing and layer 2 within it: To send a packet with custom layer 2, we have to use the sendp () method.

How to build a ping packet in Python using Scapy?

Python Scapy tutorial – Build ping packet 1 Install Python and Scapy on any linux system. The above screenshot is an ubuntu system. 2 Create Python file called scapyping.py on the ubuntu system 3 The first line imports the scapy library into the Python file 4 The second line creates an ICMP header. This is created since ping uses icmp. More ...

How to send and receive packets in Python?

When you run this in the Python environment you are using the sr1 function. The sr1 function will send a packet and then wait for an answer, keeping a count of received packets. See more here - To get the behavior you desire, you need to use the send function, just like you did when using the Scapy shell.

What is Scapy and how do I use it?

Essentially, Scapy is a tool that allows packet manipulation and can be used for multiple purposes such as: Automating logic by importing Scapy modules into a Python script Scapy can be used through the command line interface (Method 1), but can also be imported into a Python script (Method 2).


1 Answers

When you run this in the Python environment you are using the sr1 function. The sr1 function will send a packet and then wait for an answer, keeping a count of received packets. See more here -

http://www.secdev.org/projects/scapy/doc/usage.html#send-and-receive-packets-sr

To get the behavior you desire, you need to use the send function, just like you did when using the Scapy shell.

#! /usr/bin/env python

from scapy.all import send, IP, ICMP

send(IP(src="10.0.99.100",dst="10.1.99.100")/ICMP()/"Hello World")
like image 163
RyPeck Avatar answered Oct 04 '22 10:10

RyPeck