Search code examples
pythonscapypackets

Scapy - How can I hide the report of sendp\sr1 and just get the final?‏


I am working with scapy and I started to learn how to build packets (if someone has a good example on the internet to learn from it - it will be great! thanks.).

I have the next command in scapy:

srp(Ether(dst='ff:ff:ff:ff:ff:ff')/ARP(pdst=ip)/Padding(load='\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00'),timeout=2)

Which send an arp packet in layer 2. When I do this command, its giving me the next answer:

WARNING: No route found for IPv6 destination :: (no default route?) Begin emission: *Finished to send 1 packets.

Received 1 packets, got 1 answers, remaining 0 packets

00:50:56:e9:b8:b1

for the next code:

def Arp_Req(ip):
        packet = srp(Ether(dst='ff:ff:ff:ff:ff:ff')/ARP(pdst=ip)/Padding(load='\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00'),timeout=2)
        try:
                packet[0][0]
                return packet[0][0][1].hwsrc
        except IndexError:
                return "(E2)CANT FIND AN ANSWER FOR "+ip+"."

I want to hide all the report and print just the return answer. How can I do it?


Solution

  • Part of the output here come from a warning, due to IPv6, which you may avoid by disabling IPv6 support (from scapy), but you also have output generated by the function srp() itself, and for that you need to set the verbose argument:

    from scapy.config import conf  
    conf.ipv6_enabled = False
    from scapy.all import *
    
    def Arp_Req(ip):
        packet = srp(Ether(dst='ff:ff:ff:ff:ff:ff')/ARP(pdst=ip)/Padding(load='\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00'),timeout=2, verbose=0)
        try:
            packet[0][0]
            return packet[0][0][1].hwsrc
        except IndexError:
            return "(E2)CANT FIND AN ANSWER FOR "+ip+"."
    
    # example
    print Arp_Req("192.168.0.254")