网络抓包工具: 提供界面,可抓取网络数据包并显示

package Task3; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import javax.swing.*; import jpcap.JpcapCaptor; import jpcap.NetworkInterface; import jpcap.PacketReceiver; import jpcap.packet.*; import sun.tools.jar.resources.jar; public class Task3 extends JFrame{ static JTextArea ta2 = new JTextArea(); static JTextArea ta3 = new JTextArea(); static JTextArea ta4 = new JTextArea(); static JTextArea ta5 = new JTextArea(); static JTextArea ta6 = new JTextArea(); static JTextArea ta7 = new JTextArea(); static JTextArea ta8 = new JTextArea(); static JTextArea ta9 = new JTextArea(); public static void main(String args[]){ Task3 dn = new Task3("网络监听"); //dn.GrabTest(); } public Task3(String title) { super(title); setLayout(null); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setLocation(40,0); setSize(560,750); JTabbedPane tabbedPane = new JTabbedPane(); JLabel label1 = new JLabel("协议名称"); label1.setBounds(new Rectangle(50, 30, 100, 20)); JLabel label2 = new JLabel("源IP:端口"); label2.setBounds(new Rectangle(170, 30, 100, 20)); JLabel label3 = new JLabel("目的IP:端口"); label3.setBounds(new Rectangle(310, 30, 100, 20)); JLabel label4 = new JLabel("包长度"); label4.setBounds(new Rectangle(450, 30, 100, 20)); add(label1); add(label2); add(label3); add(label4); Button bt1 = new Button("监听"); bt1.addActionListener(new GrabTest()); bt1.setBounds(new Rectangle(220, 0, 70, 25)); ta2.setEditable(true); ta2.setText(" "); ta2.setBackground(Color.white); ta2.setLineWrap(true); ta3.setEditable(true); ta3.setText(" "); ta3.setBackground(Color.white); ta3.setLineWrap(true); ta4.setEditable(true); ta4.setText(" "); ta4.setBackground(Color.white); ta4.setLineWrap(true); ta5.setEditable(true); ta5.setText(" "); ta5.setBackground(Color.white); ta5.setLineWrap(true); ta2.setBounds(new Rectangle(20,50, 100, 300)); ta3.setBounds(new Rectangle(122, 50, 150, 300)); ta4.setBounds(new Rectangle(274, 50, 150, 300)); ta5.setBounds(new Rectangle(426, 50, 100, 300)); ta6.setBounds(new Rectangle(20, 352, 506, 90)); ta7.setBounds(new Rectangle(20, 444, 506, 90)); ta8.setBounds(new Rectangle(20, 536, 506, 90)); ta9.setBounds(new Rectangle(20, 628, 506, 90)); ta6.append("TCP数据包解析:"+"\n"); ta7.append("UDP数据包解析:"+"\n"); ta8.append("ARP数据包解析:"+"\n"); ta9.append("ICMP数据包解析:"+"\n"); add(bt1); add(ta2); add(ta3); add(ta4); add(ta5); add(ta5); add(ta6); add(ta7); add(ta8); add(ta9); setVisible(true); } }class GrabTest implements ActionListener{ public void actionPerformed(ActionEvent e){ try{ //获取本机上的网络接口对象数组 finalNetworkInterface[] devices = JpcapCaptor.getDeviceList(); for(int i=0; i

【网络抓包工具: 提供界面,可抓取网络数据包并显示】这题的难度在于要导入jpcap的包,非常坑爹,几次都失败。

    推荐阅读