Tcpdump.txt
资源名称:Tcpdump.rar [点击查看]
上传用户:weierdasi
上传日期:2022-08-06
资源大小:1k
文件大小:1k
源码类别:
TCP/IP协议栈
开发平台:
Java
- import jpcap.*;
- import java.sql.*;
- class Tcpdump implements JpcapHandler,Runnable
- {
- String str=null;
- public void handlePacket(Packet packet)
- {
- System.out.println(packet);
- }
- public Tcpdump(String str)
- {
- this.str=str;
- }
- public void run() //throws java.io.IOException{
- {
- Connection dbConn =null;
- PreparedStatement sta=null;
- String driverName = "com.mysql.jdbc.Driver";
- String dbURL = "jdbc:mysql://localhost:3308/mydata";
- String userName = "root";
- String userPwd = "123456";
- String insql= "insert into mypackage(srcaddress,dstaddress,type) values(?,?,?)";
- try
- {
- Class.forName(driverName);
- dbConn = DriverManager.getConnection(dbURL, userName, userPwd);
- sta=dbConn.prepareStatement(insql);
- sta.setString(1,str);
- sta.setString(2,"");
- sta.setString(3,"");
- sta.executeUpdate();
- }
- catch (Exception e)
- {
- e.printStackTrace();
- }
- finally
- {
- try
- {
- dbConn.close();
- sta.close();
- }
- catch(Exception ee)
- {
- ee.printStackTrace();
- }
- }
- }
- }