Can't extract individual fields from scapy packet
<p>I've been experimenting with scapy and Python 3 and I want to use the ARP protocol to find mac addresses of computers on the network. This is my code:</p>

<pre><code>&gt;&gt;&gt; packet = srp(Ether(dst="ff:ff:ff:ff:ff:ff")/ARP(pdst=IP_OF_HOST))
</code></pre>

<p>Then to extract the data from this packet I used the following line:</p>

<pre><code>&gt;&gt;&gt; packet[0][Ether].src
</code></pre>

<p>However for some reason this produces the error:</p>

<pre class="lang-none prettyprint-override"><code>AttributeError: 'list' object has no attribute 'src'
</code></pre>

<p>Every tutorial I read used the method I used for extracting field data, why wouldn't it work for me?</p>

<p>It has to do with the difference between the functions srp(), and srp1() (Those being for network layer 2, for layer 3 you would use sr() and sr1() respectively).</p>

<p>srp() sends the packet, and saves all packets, whether they are answered or not. To get say the source MAC address I'd do this:</p>

<pre><code>answered_packets, unanswered_packets = packet
for packet_i_sent, packet_i_received in answered_packets:
    print(packet_i_received.src)
</code></pre>

<p>srp1() sends a packet, and waits for one answer, and saves only the reply packet. This means the format is different, since you don't have to deal with the unanswered packets, and my previous method would work:</p>

<pre><code>print(packet.src)     #The [Ether] part doesn't matter, 
                      #that's just for looking fancier when you print(packet)
</code></pre>

<p>So basically I used the command srp() and tried to decode the reply like I was using srp1()</p>

python python-3.x attributes scapy arp