title: Python Active Recon - Basic Function
body: <p>I'm new to python and using scapy. Trying to make a basic active reconnaissance program to do the following:</p>
  <ul>
  <li>fetch the IP address for the given network interface (eg enp0s or lo)</li>
  <li>Should then send an ICMP request to every host in this network (can assume it is a /24 network).</li>
  <li>Detect if an ICMP reply was returned</li>
  <li>When the script has finished sending ICMP requests it should output a list of addresses for which a reply was received</li>
  </ul>
  <p>Anyone know where I'm going wrong, can't seem to figure it out...would appreciate the help of some more experienced coders to help me expand my knowledge</p>
  <p>Thank you.</p>
  <pre><code>def active_recon():
  #To get the IP address for the given network interface by using &quot;ifconfig&quot; command manually we know that enp0s3 = &quot;10.0.2.15&quot; and lo = &quot;127.0.0.1&quot;
  
  
    def filter_packets(ipaddress):
      def packet_handler(pkt):
        if(pkt[IP].src == ipaddress):
          print(pkt.summary())   
      
      return packet_handler
  
  
     #send an ICMP request to every host(IP address) in the same network (as we are assuming it's a /24 network)
    
    if(InterfaceSelected == &quot;lo&quot;): #using the global variable defined in the main function to determine which interface the user has selected
      ipaddress = &quot;127.0.0.1&quot;
      send(IP(dst=&quot;127.0.0.1&quot;)/ICMP())      #creating a packet which includes the IP header, which is neeeded to send a ping
      sr(IP(dst=&quot;127.0.0.1&quot;)/ICMP())      #detecting if a reply is returned - using sr function instead of sr1 function as this has the ability to receive multiple replies (in the event this happens)
      sniff(iface=&quot;lo&quot;, timeout=5, prn=filter_packets(ipaddress)) #5 second timeout
  
    if(InterfaceSelected == &quot;enp0s3&quot;):
      ipaddress = &quot;10.0.2.15&quot;
      send(IP(dst=&quot;10.0.2.15&quot;)/ICMP())      
      sr(IP(dst=&quot;10.0.2.15&quot;)/ICMP())  
      sniff(iface=&quot;enp0s3&quot;, timeout=5, prn=filter_packets(ipaddress))    
    
  #Output a list of MAC addresses that sent a reply
  </code></pre>