Tcpdump.txt
上传用户:weierdasi
上传日期:2022-08-06
资源大小:1k
文件大小:1k
源码类别:

TCP/IP协议栈

开发平台:

Java

  1. import jpcap.*;
  2. import java.sql.*;
  3. class Tcpdump implements JpcapHandler,Runnable
  4. {
  5.    String str=null;
  6.    public void handlePacket(Packet packet)
  7.    {
  8.      System.out.println(packet);
  9.    }
  10.    public Tcpdump(String str)
  11.    {
  12.      this.str=str;
  13.    }
  14.    public void run() //throws java.io.IOException{
  15.    {
  16.          Connection dbConn =null;
  17.          PreparedStatement sta=null;
  18.          String driverName = "com.mysql.jdbc.Driver";
  19.          String dbURL = "jdbc:mysql://localhost:3308/mydata";
  20.          String userName = "root";
  21.          String userPwd = "123456";
  22.          String insql= "insert into mypackage(srcaddress,dstaddress,type) values(?,?,?)";
  23.         try
  24.         {
  25.            Class.forName(driverName);
  26.            dbConn = DriverManager.getConnection(dbURL, userName, userPwd);
  27.            sta=dbConn.prepareStatement(insql);
  28.            sta.setString(1,str);
  29.            sta.setString(2,"");
  30.            sta.setString(3,"");
  31.            sta.executeUpdate();
  32.          }
  33.          catch (Exception e)
  34.          {
  35.            e.printStackTrace();
  36.          }
  37.          finally
  38.          {
  39.            try
  40.            {
  41.              dbConn.close();
  42.              sta.close();
  43.            }
  44.            catch(Exception ee)
  45.            {
  46.              ee.printStackTrace();
  47.            }
  48.          }
  49.      }
  50.  }