简体   繁体   中英

Filter with Jpcap

I need to filter Telnet packets using Jpcap.. how can I do it? I've tried with:

captor.setFilter("telnet", true);

but it does not work...

By calling your captor instance [ captor.loopPacket(-1,handler) ] with a handler like this :

public class TelnetReceiver implements PacketReceiver
{
    public void receivePacket(Packet p) 
    {
        if (p instanceof TCPPacket) { //Filter TCP only
            TCPPacket tcp = (TCPPacket) p;

            if(tcp.dst_port == 23 || tcp.src_port == 23)) {
                //Do something with tcp.data or other layer fields
            }
        }
    }
}

你可以过滤telnet端口(23):

captor.setFilter("port 23", true);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM