Capture my packets before sended through the network [closed]
I would like to ask if there is a way to开发者_如何学JAVA capture packets, that are about to send from my computer to others through the network.. Is it possible with some java libraries, to design sth like that?
edit i dont want a programme.. i want a way to create such a programme, written in java... I can send packets with jpcap but i dont want to create the packets, i want to take the packets that my computer will send and edit them before sending them.
In Linux (ie the Linux kernel) your goal is not so easy to achive... but you can use the same technique used by the software sniffjoke: i.e. a tunnel. In this way you can intercept all packets sent (by your applications) and so you can modify/change them (like does sniffjoke). To help you there is a project (open source) named janus ( https://github.com/evilaliv3/janus ), it overrides the actual routing table, creating a fake gateway with the aim to block packets after the kernel (on outgoing traffic) and before the kernel (on incoming traffic).
I guess, in theory, you could create an alternative "SocketImpl" class and configure your application to use it by configuring a custom socket factory as the default. This approach cannot capture the TCP/IP packets, but it could capture the data before it is written to the OS-level socket.
If you want to capture the network packets and edit them on the way through, you'll probably need to use the host OS'es IP filtering infrastructure. It will be non-portable, technically complicated, and a pain in the nether regions to configure. And even more so if you try to implement it in Java (using JNI or JNA).
(AFAIK, tools like Wireshark only allow you to see the packets and what's in them. They can't change the packets.)
精彩评论