Tracerouter in python error:<lambda>() Missing 1 required positional argument: 'r'

Asked

Viewed 272 times

0

Someone could assist me here, I spent a few days trying to solve this business in my code and unfortunately I could not solve.

The operating system I am using is Windows 10.

My problem is on the bold line.

from scapy.all import *

target = input("Informe um alvo: ")
destport = input("Porta de destino: ")

port = int(destport)

ans,unans=sr(IP(dst=target,ttl=(1,30))/TCP(dport=port,flags="S"))

ans.summary(lambda s,r: r.sprintf("{IP:%IP.src%}\t{ICMP:%ICMP.type%}\t{TCP:%TCP.flags%}"))

The mistake you’re making is this: Typeerror: () Missing 1 required positional argument: 'r'

What should I change or perform some installation in order to solve ?

From now on Thank you :)

Note: I’ve made several changes to this line of code, and I’ve already researched several sites to try to get the solution, the problem is, I don’t understand enough about this subject, I’m running a course for this, but the instructor does not answer the questions and did not explain very well what this line of code does. So I’d like someone to explain to me exactly how ans.Ummary and the lambda.

This would be the expected output of this whole script.

inserir a descrição da imagem aqui

  • How is the output of ans? You can put a toothpick here for us?

  • Ready I put the result of the teacher

1 answer

0

Lambda is basically a function, for example:

def vezes_dois(n):
   return 2 * n

May be replaced by

vezes_dois = lambda n: 2 * n

What’s happening is that your lambda requires s and r, but you’re only getting it. A slightly simpler version of your code:

from scapy.all import *

target = input("Informe um alvo: ")
destport = input("Porta de destino: ")

port = int(destport)

ans, unans = sr( IP(dst = target,ttl = (1,30) ) / TCP(dport = port, flags = "S") )

def funcao(s, r):
    return r.sprintf("{IP:%IP.src%}\t{ICMP:%ICMP.type%}\t{TCP:%TCP.flags%}")

ans.summary(funcao)

I believe that the s shouldn’t be there, after all, you don’t even use the s.

from scapy.all import *

target = input("Informe um alvo: ")
destport = input("Porta de destino: ")

port = int(destport)

ans, unans = sr( IP(dst = target,ttl = (1,30) ) / TCP(dport = port, flags = "S") )

def funcao(r):
    return r.sprintf("{IP:%IP.src%}\t{ICMP:%ICMP.type%}\t{TCP:%TCP.flags%}")

ans.summary(funcao)

I hope I’ve helped :)

Browser other questions tagged

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