Create mocked http session with scapy python
Question: How can i create a HTTP session and save the packets of it? i have got this
code:

import logging logging.getLogger("scapy.runtime").setLevel(logging.ERROR)

from scapy.all import *

get='GET / HTTP/1.0\n\n'

ip=IP(dst="www.google.com")

port=RandNum(1024,65535)

SYN=ip/TCP(sport=port, dport=80, flags="S", seq=42)

SYNACK=sr1(SYN)

ACK=ip/TCP(sport=SYNACK.dport, dport=80, flags="A", seq=SYNACK.ack,
ack=SYNACK.seq + 1) / get

reply,error=sr(ACK)

but in my code i don't want to send any packets just to get the
answer(simulate the situation of the sending functions of SYNACK=sr1(SYN) and
reply,error=sr(ACK) without really using them).. i want to simulate the
session between two ips(with their ports) and with the payload and then save
everything as packets as cap file.. how can i do this?


Answer: The jargon you're looking for is 'mocking'. Later versions of python unit
testing have
[unittest.mock](https://docs.python.org/3/library/unittest.mock.html) and
there are also external libraries available that can pretend to be external
sources like files, databases and websites that allow you to test your code.

