Creating an ARPING

Asked

Viewed 118 times

0

#!/usr/bin/python3
#Fazer arping de conexao

import sys
from datetime import datetime
from scapy.all import *

try:
    interface = input ("\n[*] Set interface: ")
    ips = input("[*] Set IP RANGE or Network: ")
except KeyboardInterrupt:
    print("\n user aborted")
    sys.exit()

print("Scanning...")
start_time = datetime.now()

conf.verb = 0

ans,unans = srp(Ether(dst = "ff:ff:ff:ff:ff:ff")/ARP(pdst = ips), timeout = 2, iface = interface ,inter= 0.1)

print("\n\tMAC\t\tIP\n")

for snd,rcv in ans:
    print(rcv.sprintf("%Ether.src% - %ARP.psrc%"))

stop_time = datetime.now()
total_time = stop_time - start_time
print("\n[*] Scan Completed")
print("[*] Scan Duration: %s" %(total_time))

This code was picked up online for study. I couldn’t understand two lines:

ans,unans = srp(Ether(dst = "ff:ff:ff:ff:ff:ff")/ARP(pdst = ips), timeout = 2, iface = interface ,inter= 0.1)

and

 print(rcv.sprintf("%Ether.src% - %ARP.psrc%"))

What does it mean ,inter= 0.1 and rcv.sprintf ? What is conf.verb = 0 ?

1 answer

1


ans, unans = srp(Ether(dst = "ff:ff:ff:ff:ff:ff")/ARP(pdst = ips), timeout = 2, 
iface = interface, inter= 0.1)

The function srp has the same purpose as sr (explained here), the difference is that srp send and receive the packets in layer 2, and sr in layer 3. In this code you are using the Ethernet.

According to the documentation, the parameter inter is used to specify the time in seconds waiting between each packet sent. conf.verb is to enable or disable the verbose mode, by default is 1 (enabled), to disable, the value is 0.

The sprintf as explained here, does the custom formatting of the results. It is something similar to this:

class Formatacao:        
    def sprintf(self, formato):
        while "%" in formato:
            final = formato.rindex("%")
            inicio  = formato[final:].index("%")

            formato = formato[:final] + formato[final + inicio + 1:]
            palavras = formato.split()

        for palavra in palavras:
            if hasattr(self, palavra):
                valor = getattr(self, palavra)

                formato = formato.replace(palavra, str(valor))

        return formato

class Pessoa(Formatacao):
    def __init__(self, nome, sexo, peso, idade):
        self.nome = nome
        self.sexo = sexo
        self.peso = peso
        self.idade = idade

In the Scapy, this formatting process is much more complex, with more variables and checks, in the above code if you pass a word between %, the method hasattr will check whether the word is a name of some object in the class Pessoa, if it is, we take its value with the function getattr and replaced the word by the value with the function replace.

pessoa = Pessoa("Joao", "M", 70, 21)
print (pessoa.sprintf("%nome% tem %idade% anos"))

See demonstração

You can see the function code sprintf of Scapy here.

Whenever you have any questions look also at the documentation!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.