Активная разведка Python — Базовая функция

#python #scapy

Вопрос:

Я новичок в python и использую scapy. Попытка создать базовую программу активной разведки для выполнения следующих действий:

  • получите IP — адрес для данного сетевого интерфейса (например, enp0s или lo)
  • Затем следует отправить запрос ICMP каждому хосту в этой сети (можно предположить, что это сеть /24).
  • Определите, был ли возвращен ответ ICMP
  • Когда скрипт завершит отправку запросов ICMP, он должен вывести список адресов, на которые был получен ответ

Кто-нибудь знает, где я ошибаюсь, кажется, не может этого понять…буду признателен за помощь более опытных программистов, которые помогут мне расширить мои знания

Спасибо.

 def active_recon(): #To get the IP address for the given network interface by using "ifconfig" command manually we know that enp0s3 = "10.0.2.15" and lo = "127.0.0.1"    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 == "lo"): #using the global variable defined in the main function to determine which interface the user has selected  ipaddress = "127.0.0.1"  send(IP(dst="127.0.0.1")/ICMP()) #creating a packet which includes the IP header, which is neeeded to send a ping  sr(IP(dst="127.0.0.1")/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="lo", timeout=5, prn=filter_packets(ipaddress)) #5 second timeout   if(InterfaceSelected == "enp0s3"):  ipaddress = "10.0.2.15"  send(IP(dst="10.0.2.15")/ICMP())   sr(IP(dst="10.0.2.15")/ICMP())   sniff(iface="enp0s3", timeout=5, prn=filter_packets(ipaddress))    #Output a list of MAC addresses that sent a reply