1

I used to code with Scapy in python. Now I'm going to manipulate packets in a pcap file using java. For example I need to read the pcap file and then alter one packet's source ip.

Actually, I've altered one field using jNetStream library, but I don't know how to write the modified packet to pcap file

EDIT:

I've just provided some codes which belong to packet modification.

Decoder decoder = new Decoder("fileName.pcap");
while ((packet = decoder.nextPacket()) != null) {
    new_saddr = InetAddress.getByName("1.1.1.1").getAddress();
    saddr.setAddress(new_saddr);

As it could be seen, the new source Ip Address has been set. Now I want to write the whole packets to a new pcap file but I don't know how to do it. Any help would be appreciated.

Mojtaba Yousefi
  • 626
  • 1
  • 9
  • 27
  • It may be useful to provide your code – Chris J Jul 18 '16 at 12:50
  • @ChrisJ Thanks for your comment. I've done it. – Mojtaba Yousefi Jul 19 '16 at 05:17
  • 1
    Have you looked at the documentation for jnetpcap? It describes how to dump captured packages to a file: http://jnetpcap.com/?q=node/69 – Ben Damer Aug 01 '16 at 17:26
  • @BenDamer Yes I already checked it out. If I use dump method, then I won't be able to manipulate packets. I jest could dump it into another pcap file. – Mojtaba Yousefi Aug 02 '16 at 09:57
  • 1
    Why not? PcapDumper.dump has the ability to dump individual packets to a Pcap file. Just load the original file, manipulate each packet, and dump each to a target file. – Ben Damer Aug 02 '16 at 15:57
  • @BenDamer That's great. But I had problem with manipulating the packet. For example there was no method to set ip address. I'd be thankful if you help me out with an example. Thanks indeed – Mojtaba Yousefi Aug 03 '16 at 12:59

0 Answers0