java - How will I be able to printout the captured packets using pcap.loop() with a parameter of Pcap.LOOP_INFINITE into the JTextArea? -
i'm quite new jnetpcap
, i'm still finding way around it, i'm trying build packet sniffer project, lately i'm trying printout packet info jtextarea
appending info pcap.loop()
using, when set first parameter using specific integer value allow 5 pcap.loop()
outputs 5 packets had been captured, want continuously capture , output packet until press button stop. syntax below shows packet handler.
pcappackethandler<string> jpackethandler = new pcappackethandler<string>() { public void nextpacket(pcappacket packet, string user) { // system.out.printf included check if code works in non gui fashion system.out.printf("received packet @ %s caplen=%-4d len=%-4d %s\n", new date(packet.getcaptureheader().timestampinmillis()), packet.getcaptureheader().caplen(), // length captured packet.getcaptureheader().wirelen(), // original length user // user supplied object ); date = new date(packet.getcaptureheader().timestampinmillis()); int b = packet.getcaptureheader().caplen(); int c = packet.getcaptureheader().wirelen(); string d = user; pckttextarea.append("received packet @ " + + " caplen=" + integer.tostring(b) + " len=" + integer.tostring(b) + user + "\n" ); pckttextarea.setforeground(color.red); pckttextarea.setfont(font); } };
now bit here pckttextarea utilize append
print out info in textarea:
pckttextarea.append("received packet @ " + + " caplen=" + integer.tostring(b) + " len=" + integer.tostring(b) + user + "\n" ); pckttextarea.setforeground(color.red); pckttextarea.setfont(font);
and pcap.loop
having problem with, if replace allow 5 printed in jtextarea
when set pcap.loop_infinte
prints info through console not in gui jtextarea:
int = pcap.loop_infinite; pcap.loop(i , jpackethandler, " "); /*************************************************************************** * lastly thing close pcap handle **************************************************************************/ pcap.close();
is because has finish loop before printing info out in textarea?
i assume run code in thread. utilize swingutilities.invokeandwait
phone call pckttextarea.append()
code
java swing pcap libpcap jnetpcap
No comments:
Post a Comment