Creating an ARPING

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 has been taken on the internet for studies. I could not 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 ?

    
asked by anonymous 13.08.2016 / 00:59

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 srp function has the same purpose as sr (explained here ), the difference is that srp sends and receives packets in the layer 2 , and sr in layer 3 . In this code you are using the Ethernet .

According to the documentation, the inter parameter is used to specify the time in seconds of waiting between each packet sent. conf.verb is to enable or disable 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 looks something like 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 Scapy , this formatting process is much more complex, with more variables and checks, in the above code if you pass a word between % , the hasattr will check if the word is a name of some object of class Pessoa if so, we'll take your value with getattr and replace the word by the value with the function replace .

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

View demonstração

You can see the code for the% Scapy role here .

Whenever you have any questions, check out documentation . / a>!

    
21.08.2016 / 00:10