Skip to content

Commit

Permalink
add pcap_fix_udp_len.py and remove turn example
Browse files Browse the repository at this point in the history
  • Loading branch information
sreimers committed Oct 19, 2023
1 parent 12fee70 commit c066832
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 3 deletions.
10 changes: 7 additions & 3 deletions sipp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,21 @@ sudo build/sipp -sf scenarios/uac_pcap.xml 127.0.0.1 -m 1

### Manipulating

Reorder
#### Reorder

```bash
editcap -r g711a.pcap tmp1 2-3 # dump packets 2-3
editcap -r -t 0.07 g711a.pcap tmp2 1 # dump packet 1 and manipulate timestamp
editcap g711a.pcap tmp3 1-3 # exclude packets 1-3
mergecap -w out.pcap -a tmp1 tmp2 tmp3
```

Drop
#### Drop

```bash
editcap g711a.pcap out.pcap 2-3 # drop packets 2-3
```

#### Remove TURN (4 Bytes, Offset 42 Bytes) encapsulation

editcap -L -C42:4 in.pcap tmp.pcap
./pcap_fix_udp_len.py tmp.pcap out.pcap 4
34 changes: 34 additions & 0 deletions sipp/pcap_fix_udp_len.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/usr/bin/env python

import argparse
from scapy.all import *

def update_bytes_from_packet(packet, rbytes):
if UDP in packet:
# Check if the packet contains a UDP layer
packet[UDP].len = packet[UDP].len - int(rbytes)
packet[IP].len = packet[IP].len - int(rbytes)
packet[UDP].chksum = None # Recalculate UDP checksum
packet[IP].chksum = None # Recalculate IP checksum

def main():
parser = argparse.ArgumentParser(description="Update IP/UDP length.")
parser.add_argument("input_file", help="Input PCAP file")
parser.add_argument("output_file", help="Output PCAP file")
parser.add_argument("rbytes", help="bytes to remove")

args = parser.parse_args()

# Load the PCAP file
packets = rdpcap(args.input_file)

for packet in packets:
update_bytes_from_packet(packet, args.rbytes)

# Save the modified PCAP file
wrpcap(args.output_file, packets)

print("PCAP file successfully modified and saved as", args.output_file)

if __name__ == "__main__":
main()

0 comments on commit c066832

Please sign in to comment.