Search code examples
pythonscapyarp

Can't import Scapy arping() method


from scapy.layers.l2 import arping
from scapy.all import *

def scan(ip):
    scapy.layers.l2.arping(ip)

scan('192.168.0.1')

Can someone explain why those imports need to look like this?

I saw in a tutorial that for the guy was enough to "import scapy.all as scapy" and he had that arping() method working fine.

When I delete "from scapy.all import *" the reference in scan function to scapy is gone. Shouldn't it be gone if I'm importing this "scapy.layers.l2..."?


Solution

  • If you import as you have there, you'd use the name arping directly:

    from scapy.layers.l2 import arping
    
    def scan(ip):
        arping(ip)
    

    If you imported as they had, you'd do this:

    import scapy.all as scapy
    
    def scan(ip):
        scapy.arping(ip)