mirror of
https://github.com/The-Art-of-Hacking/h4cker.git
synced 2024-12-18 10:56:09 +00:00
Update another_scapy_sniffer_walkthrough.md
This commit is contained in:
parent
c3098883a2
commit
46886af1b2
@ -21,3 +21,21 @@ sniff(prn=packet_callback, filter="tcp and host 10.1.1.2 and port 80", count=1)
|
||||
```
|
||||
It's important to note that capturing packets may require root/admin permissions.
|
||||
|
||||
## Saving to a pcap file
|
||||
|
||||
Here is a modified version of the script that saves the captured packets to a pcap file:
|
||||
|
||||
```
|
||||
from scapy.all import *
|
||||
|
||||
# Define a callback function
|
||||
def packet_callback(packet):
|
||||
print(packet.show())
|
||||
wrpcap("captured_packets.pcap", packet, append=True)
|
||||
|
||||
# Use the sniff() function to capture packets
|
||||
sniff(prn=packet_callback, filter="tcp", count=1)
|
||||
|
||||
```
|
||||
|
||||
This script uses the `wrpcap()` function from Scapy to save the captured packets to a `pcap` file named "captured_packets.pcap". The `append=True` argument is used to append the packets to the file instead of overwriting it.
|
||||
|
Loading…
Reference in New Issue
Block a user