title: sending ICMP packets in scapy and choosing the correct interface
body: <p>Can we use the srp() function for a Layer 3 ICMP packet? I see that when we craft an ICMP echo-request packet and use the sr() to send/receive, we do NOT see it getting sent out of the interface , hence no response from the destination. But the same packet if we use the srp() function we see the response. When should we use sr() and when srp()? In the documentation it states sr() is to be used for L3 packet and srp() to be used for L2? But in my case I am not sure why sr() is not working for an ICMP packet? Can some experts please help me understand?</p>
  
  <p>Also can someone let me know if "iface" argument is needed always. Without that how will scapy know through which interface its supposed to send the packet?</p>
  
  <p><strong>Case 1: sr() function with iface as argument:</strong> </p>
  
  <pre><code>sr(icmp,iface="eth0")
  </code></pre>
  
  <p>Begin emission:</p>
  
  <pre><code>WARNING: Mac address to reach destination not found. Using broadcast.
  Finished to send 1 packets.
  ^C
  Received 0 packets, got 0 answers, remaining 1 packets
  (&lt;Results: TCP:0 UDP:0 ICMP:0 Other:0&gt;, &lt;Unanswered: TCP:0 UDP:0 ICMP:1 Other:0&gt;)
  </code></pre>
  
  <p>Above I do NOT see any ICMP response from the IP 192.168.25.1</p>
  
  <p><strong>Case 2: sr() function without iface:</strong></p>
  
  <pre><code>sr(icmp)   
  .Begin emission:
  ......WARNING: Mac address to reach destination not found. Using broadcast.
  .Finished to send 1 packets.
  ...............................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................^C
  Received 887 packets, got 0 answers, remaining 1 packets
  (&lt;Results: TCP:0 UDP:0 ICMP:0 Other:0&gt;, &lt;Unanswered: TCP:0 UDP:0 ICMP:1 Other:0&gt;)
  </code></pre>
  
  <p>If you see above the received packets is more but I do not see any ICMP response.</p>
  
  <p><strong>Case 3: Sending the ICMP packet with srp() instead of sr():</strong></p>
  
  <pre><code>srp(icmp,iface="eth0")
  Begin emission:
  Finished to send 1 packets.
  *
  Received 1 packets, got 1 answers, remaining 0 packets
  (&lt;Results: TCP:0 UDP:0 ICMP:1 Other:0&gt;, &lt;Unanswered: TCP:0 UDP:0 ICMP:0 Other:0&gt;)
  </code></pre>
  
  <p><strong>Here I used the srp() function instead of sr() function and now I see that the ICMP echo request was sent properly and I received the response also.</strong>                                                          </p>
  
  <pre><code>&gt;&gt;&gt; icmp.show2()
  ###[ Ethernet ]###
    dst: 02:00:00:11:01:03
    src: 02:00:20:ee:64:01
    type: 0x800
  ###[ IP ]###
       version: 4L
       ihl: 5L
       tos: 0x0
       len: 28
       id: 1
       flags:
       frag: 0L
       ttl: 64
       proto: icmp
       chksum: 0xc78c
       src: 192.168.25.2
       dst: 192.168.25.1
       \options\
  ###[ ICMP ]###
          type: echo-request
          code: 0
          chksum: 0xf7ff
          id: 0x0
          seq: 0x0
  &gt;&gt;&gt;                  
  </code></pre>