Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Practical No.:1
- Aim: Program to take database backup
- Code:
- import java.io.FileWriter;
- import java.sql.Connection;
- import java.sql.DriverManager;
- public class backup extends javax.swing.JFrame {
- public backup() {
- initComponents();
- }
- @SuppressWarnings("unchecked")
- // <editor-fold defaultstate="collapsed" desc="Generated Code">
- private void initComponents() {
- jLabel1 = new javax.swing.JLabel();
- jLabel3 = new javax.swing.JLabel();
- jLabel9 = new javax.swing.JLabel();
- jLabel10 = new javax.swing.JLabel();
- jLabel11 = new javax.swing.JLabel();
- jLabel12 = new javax.swing.JLabel();
- jLabel13 = new javax.swing.JLabel();
- jLabel2 = new javax.swing.JLabel();
- jTextField1 = new javax.swing.JTextField();
- jTextField2 = new javax.swing.JTextField();
- jTextField3 = new javax.swing.JTextField();
- jTextField4 = new javax.swing.JTextField();
- jTextField5 = new javax.swing.JTextField();
- jTextField6 = new javax.swing.JTextField();
- jButton1 = new javax.swing.JButton();
- jButton2 = new javax.swing.JButton();
- jLabel1.setText("jLabel1");
- setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
- jLabel9.setText("My SQl path:");
- jLabel10.setText("My SQL user:");
- jLabel11.setText("My SQL password:");
- jLabel12.setText("Database name:");
- jLabel13.setText("Backup Path:");
- jLabel2.setText("Backup file name:");
- jTextField3.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jTextField3ActionPerformed(evt);
- }
- });
- jTextField4.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jTextField4ActionPerformed(evt);
- }
- });
- jTextField5.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jTextField5ActionPerformed(evt);
- }
- });
- jTextField6.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jTextField6ActionPerformed(evt);
- }
- });
- jButton1.setText("Backup");
- jButton1.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jButton1ActionPerformed(evt);
- }
- });
- jButton2.setText("Clear");
- jButton2.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jButton2ActionPerformed(evt);
- }
- });
- javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
- getContentPane().setLayout(layout);
- layout.setHorizontalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addContainerGap()
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addComponent(jLabel11)
- .addGap(18, 18, 18)
- .addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, 468, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addGroup(layout.createSequentialGroup()
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(jLabel10)
- .addComponent(jLabel9)
- .addComponent(jLabel12))
- .addGap(28, 28, 28)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
- .addComponent(jTextField2)
- .addComponent(jTextField1)
- .addComponent(jTextField5, javax.swing.GroupLayout.DEFAULT_SIZE, 468, Short.MAX_VALUE)
- .addComponent(jTextField4))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 123, Short.MAX_VALUE)
- .addComponent(jLabel3)))
- .addContainerGap(130, Short.MAX_VALUE))
- .addGroup(layout.createSequentialGroup()
- .addComponent(jLabel13)
- .addContainerGap())
- .addGroup(layout.createSequentialGroup()
- .addComponent(jLabel2)
- .addGap(18, 18, 18)
- .addComponent(jTextField6, javax.swing.GroupLayout.PREFERRED_SIZE, 468, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addGap(0, 0, Short.MAX_VALUE))))
- .addGroup(layout.createSequentialGroup()
- .addGap(54, 54, 54)
- .addComponent(jButton1)
- .addGap(242, 242, 242)
- .addComponent(jButton2)
- .addGap(0, 0, Short.MAX_VALUE))
- );
- layout.setVerticalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addGap(0, 0, Short.MAX_VALUE)
- .addComponent(jLabel3)
- .addGap(163, 163, 163))
- .addGroup(layout.createSequentialGroup()
- .addContainerGap()
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(jLabel9)
- .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addGap(18, 18, 18)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(jLabel10)
- .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addGap(18, 18, 18)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(jLabel11)
- .addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addGap(18, 18, 18)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(jTextField4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addComponent(jLabel12))
- .addGap(18, 18, 18)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(jLabel13)
- .addComponent(jTextField5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addGap(18, 18, 18)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(jLabel2)
- .addComponent(jTextField6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 31, Short.MAX_VALUE)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(jButton1)
- .addComponent(jButton2))
- .addGap(23, 23, 23))
- );
- pack();
- }// </editor-fold>
- private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
- try {
- Class.forName("com.mysql.jdbc.Driver");
- Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/"+jTextField4.getText(),jTextField2.getText(),jTextField3.getText());
- FileWriter fos = new FileWriter( jTextField5.getText()+"\\mycmd.bat");
- String cmd = "set path =%path%;" + jTextField1.getText() + ";+\n";
- cmd+= "mysqldump -u" + jTextField2.getText() + " -p" + jTextField3.getText() + "" + jTextField4.getText()+">"+ jTextField5.getText()+"\\"+jTextField6.getText();
- fos.write(cmd);
- fos.close();
- Runtime rt = Runtime.getRuntime();
- rt.exec("cmd.exe /c start"+jTextField5.getText()+"\\mycmd.bat");
- System.out.println("Backup completed successfully");
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
- jTextField1.setText(null);
- jTextField2.setText(null);
- jTextField3.setText(null);
- jTextField4.setText(null);
- jTextField5.setText(null);
- jTextField6.setText(null);
- }
- /**
- * @param args the command line arguments
- */
- public static void main(String args[]) {
- /* Set the Nimbus look and feel */
- //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
- /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
- * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
- */
- try {
- for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
- if ("Nimbus".equals(info.getName())) {
- javax.swing.UIManager.setLookAndFeel(info.getClassName());
- break;
- }
- }
- } catch (ClassNotFoundException ex) {
- java.util.logging.Logger.getLogger(backup.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (InstantiationException ex) {
- java.util.logging.Logger.getLogger(backup.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (IllegalAccessException ex) {
- java.util.logging.Logger.getLogger(backup.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (javax.swing.UnsupportedLookAndFeelException ex) {
- java.util.logging.Logger.getLogger(backup.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- }
- //</editor-fold>
- /* Create and display the form */
- java.awt.EventQueue.invokeLater(new Runnable() {
- public void run() {
- new backup().setVisible(true);
- }
- });
- }
- // Variables declaration - do not modify
- private javax.swing.JButton jButton1;
- private javax.swing.JButton jButton2;
- private javax.swing.JLabel jLabel1;
- private javax.swing.JLabel jLabel10;
- private javax.swing.JLabel jLabel11;
- private javax.swing.JLabel jLabel12;
- private javax.swing.JLabel jLabel13;
- private javax.swing.JLabel jLabel2;
- private javax.swing.JLabel jLabel3;
- private javax.swing.JLabel jLabel9;
- private javax.swing.JTextField jTextField1;
- private javax.swing.JTextField jTextField2;
- private javax.swing.JTextField jTextField3;
- private javax.swing.JTextField jTextField4;
- private javax.swing.JTextField jTextField5;
- private javax.swing.JTextField jTextField6;
- // End of variables declaration
- }
- Output:
- Practical No.:2
- Aim: Program to restore database
- Code:
- import java.io.FileWriter;
- import java.sql.*;
- import java.util.logging.Level;
- import java.util.logging.Logger;
- public class MySQLRestore extends javax.swing.JFrame {
- public MySQLRestore() {
- initComponents();
- }
- @SuppressWarnings("unchecked")
- // <editor-fold defaultstate="collapsed" desc="Generated Code">
- private void initComponents() {
- jLabel1 = new javax.swing.JLabel();
- jLabel2 = new javax.swing.JLabel();
- jLabel3 = new javax.swing.JLabel();
- jLabel4 = new javax.swing.JLabel();
- jLabel5 = new javax.swing.JLabel();
- jLabel6 = new javax.swing.JLabel();
- jButton1 = new javax.swing.JButton();
- mysqlpath = new javax.swing.JTextField();
- mysqluser = new javax.swing.JTextField();
- mysqlpass = new javax.swing.JTextField();
- dbname = new javax.swing.JTextField();
- backuppath = new javax.swing.JTextField();
- filename = new javax.swing.JTextField();
- jButton2 = new javax.swing.JButton();
- setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
- setTitle("MySQL Restore");
- jLabel1.setText("MySQL Path :");
- jLabel2.setText("MySQL User :");
- jLabel3.setText("MySQL Password:");
- jLabel4.setText("Database Name :");
- jLabel5.setText("Backup Path :");
- jLabel6.setText("Backup File Name :");
- jButton1.setText("Restore");
- jButton1.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jButton1ActionPerformed(evt);
- }
- });
- mysqlpath.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- mysqlpathActionPerformed(evt);
- }
- });
- mysqluser.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- mysqluserActionPerformed(evt);
- }
- });
- jButton2.setText("Clear");
- jButton2.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jButton2ActionPerformed(evt);
- }
- });
- javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
- getContentPane().setLayout(layout);
- layout.setHorizontalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addContainerGap()
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
- .addGroup(layout.createSequentialGroup()
- .addComponent(jLabel1)
- .addGap(2, 2, 2)
- .addComponent(mysqlpath, javax.swing.GroupLayout.PREFERRED_SIZE, 226, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addGroup(layout.createSequentialGroup()
- .addComponent(jLabel2)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(mysqluser))
- .addGroup(layout.createSequentialGroup()
- .addComponent(jLabel3)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(mysqlpass))
- .addGroup(layout.createSequentialGroup()
- .addComponent(jLabel4)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(dbname))
- .addGroup(layout.createSequentialGroup()
- .addComponent(jLabel5)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(backuppath))
- .addGroup(layout.createSequentialGroup()
- .addComponent(jLabel6)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(filename))
- .addGroup(layout.createSequentialGroup()
- .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 161, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addGap(18, 18, 18)
- .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 165, javax.swing.GroupLayout.PREFERRED_SIZE)))
- .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
- );
- layout.setVerticalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addContainerGap()
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(jLabel1)
- .addComponent(mysqlpath, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(jLabel2)
- .addComponent(mysqluser, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(jLabel3)
- .addComponent(mysqlpass, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(jLabel4)
- .addComponent(dbname, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(jLabel5)
- .addComponent(backuppath, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(jLabel6)
- .addComponent(filename, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(jButton1)
- .addComponent(jButton2))
- .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
- );
- pack();
- }// </editor-fold>
- private void mysqlpathActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- }
- private void mysqluserActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- }
- private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
- String db=dbname.getText();
- String user=mysqluser.getText();
- String pass=mysqlpass.getText();
- String backupPath=backuppath.getText();
- String path=mysqlpath.getText();
- String fname=filename.getText();
- try {
- Class.forName("com.mysql.jdbc.Driver");
- Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/"+db,user,pass);
- FileWriter fos=new FileWriter(backupPath+"\\mycmd.bat");
- String cmd="set path=%path%;"+path+";\n";
- cmd+="mysql -u"+user+ " -p"+pass+" "+db+"<"+ backupPath+"\\"+fname;
- fos.write(cmd);
- fos.close();
- Runtime rt=Runtime.getRuntime();
- rt.exec("cmd.exe /c start "+backupPath+"\\mycmd.bat");
- System.out.println("Restore completed Successfully.");
- } catch (Exception ex) {
- Logger.getLogger(MySQLBackup.class.getName()).log(Level.SEVERE, null, ex);
- }
- }
- private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- mysqlpath.setText("");
- mysqluser.setText("");
- mysqlpass.setText("");
- dbname.setText("");
- backuppath.setText("");
- filename.setText("");
- }
- public static void main(String args[]) {
- /* Set the Nimbus look and feel */
- //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
- try {
- for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
- if ("Nimbus".equals(info.getName())) {
- javax.swing.UIManager.setLookAndFeel(info.getClassName());
- break;
- }
- }
- } catch (ClassNotFoundException ex) {
- java.util.logging.Logger.getLogger(MySQLBackup.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (InstantiationException ex) {
- java.util.logging.Logger.getLogger(MySQLBackup.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (IllegalAccessException ex) {
- java.util.logging.Logger.getLogger(MySQLBackup.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (javax.swing.UnsupportedLookAndFeelException ex) {
- java.util.logging.Logger.getLogger(MySQLBackup.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- }
- //</editor-fold>
- /* Create and display the form */
- java.awt.EventQueue.invokeLater(new Runnable() {
- public void run() {
- new MySQLRestore().setVisible(true);
- }
- });
- }
- // Variables declaration - do not modify
- private javax.swing.JTextField backuppath;
- private javax.swing.JTextField dbname;
- private javax.swing.JTextField filename;
- private javax.swing.JButton jButton1;
- private javax.swing.JButton jButton2;
- private javax.swing.JLabel jLabel1;
- private javax.swing.JLabel jLabel2;
- private javax.swing.JLabel jLabel3;
- private javax.swing.JLabel jLabel4;
- private javax.swing.JLabel jLabel5;
- private javax.swing.JLabel jLabel6;
- private javax.swing.JTextField mysqlpass;
- private javax.swing.JTextField mysqlpath;
- private javax.swing.JTextField mysqluser;
- // End of variables declaration
- }
- Output :
- Practical No.: 3
- Aim: Use of driveImageXml to take backup and restore data
- Code:
- Steps for Backup:
- 1. Choose drive to take Backup.
- 2. Open DriveImage XML software and select target drive.
- 3. Rename backup file name if needed.
- 4. Below is the files generated after backup.
- Steps for Recovery of Drive :
- Here we are deleting all the contents of drive and then restoring the same.
- 1. Click Restore option in DriveImage XML software and select target Disk.
- 2. Select the backup file path and click next.
- 3. Then select targeted drive and click next.
- 4. Enter Disk name in the dialog box and click Ok.
- Drive contents has been restored.
- Practical No.: 4
- Aim: Write a program to log files
- Code:
- import java.io.FileWriter;
- class createlog
- {
- public static void main(String s[])
- {
- try
- {
- String cmd="WMIC /OUTPUT:D:\\LIST2.html PROCESS get name,processid,creationdate /format:hform";
- FileWriter fos=new FileWriter("D:\\mycmd.bat");
- fos.write(cmd);
- fos.close();
- Runtime rt=Runtime.getRuntime();
- rt.exec("cmd.exe /c start D:\\mycmd.bat");
- }
- catch(Exception e)
- {
- e.printStackTrace();
- }
- }
- }
- Output:
- Practical No.: 5
- Aim: Program to display filepath in directory
- Code:
- import java.io.File;
- import java.util.ArrayList;
- public class filesearch extends javax.swing.JFrame {
- String fileName;
- File dir;
- public filesearch() {
- initComponents();
- }
- @SuppressWarnings("unchecked")
- // <editor-fold defaultstate="collapsed" desc="Generated Code">
- private void initComponents() {
- jLabel1 = new javax.swing.JLabel();
- jLabel2 = new javax.swing.JLabel();
- jTextField1 = new javax.swing.JTextField();
- jTextField2 = new javax.swing.JTextField();
- jButton1 = new javax.swing.JButton();
- jButton2 = new javax.swing.JButton();
- jScrollPane1 = new javax.swing.JScrollPane();
- jTextArea1 = new javax.swing.JTextArea();
- setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
- jLabel1.setText("Enter directory to be searched");
- jLabel2.setText("Enter file to be searched");
- jButton1.setText("Search");
- jButton1.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jButton1ActionPerformed(evt);
- }
- });
- jButton2.setText("Clear");
- jButton2.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jButton2ActionPerformed(evt);
- }
- });
- jTextArea1.setColumns(20);
- jTextArea1.setRows(5);
- jScrollPane1.setViewportView(jTextArea1);
- javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
- getContentPane().setLayout(layout);
- layout.setHorizontalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addContainerGap()
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(jScrollPane1)
- .addGroup(layout.createSequentialGroup()
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(jLabel1)
- .addComponent(jLabel2))
- .addGap(18, 18, 18)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(jTextField1)
- .addComponent(jTextField2, javax.swing.GroupLayout.DEFAULT_SIZE, 215, Short.MAX_VALUE)))
- .addGroup(layout.createSequentialGroup()
- .addComponent(jButton1)
- .addGap(27, 27, 27)
- .addComponent(jButton2)
- .addGap(0, 0, Short.MAX_VALUE)))
- .addContainerGap())
- );
- layout.setVerticalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addContainerGap()
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(jLabel1)
- .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(jLabel2)
- .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addGap(42, 42, 42)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(jButton1)
- .addComponent(jButton2))
- .addGap(18, 18, 18)
- .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 132, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addContainerGap(28, Short.MAX_VALUE))
- );
- pack();
- }// </editor-fold>
- private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
- jTextArea1.setText("");
- dir = new File(jTextField1.getText());
- search(dir);
- }
- private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
- jTextField1.setText("");
- jTextField2.setText("");
- jTextArea1.setText("");
- }
- public void search(File file) {
- fileName = jTextField2.getText();
- if (file.isDirectory()) {
- for (File temp : file.listFiles()) {
- if (temp.isDirectory()) {
- search(temp);
- } else {
- if (fileName.equals(temp.getName().toLowerCase())) {
- jTextArea1.append(temp.getAbsoluteFile().toString() + "\n");
- }
- }
- }
- } else {
- System.out.println(file.getAbsoluteFile() + "Permission denied");
- }
- }
- /**
- * @param args the command line arguments
- */
- public static void main(String args[]) {
- /* Set the Nimbus look and feel */
- //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
- /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
- * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
- */
- try {
- for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
- if ("Nimbus".equals(info.getName())) {
- javax.swing.UIManager.setLookAndFeel(info.getClassName());
- break;
- }
- }
- } catch (ClassNotFoundException ex) {
- java.util.logging.Logger.getLogger(filesearch.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (InstantiationException ex) {
- java.util.logging.Logger.getLogger(filesearch.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (IllegalAccessException ex) {
- java.util.logging.Logger.getLogger(filesearch.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (javax.swing.UnsupportedLookAndFeelException ex) {
- java.util.logging.Logger.getLogger(filesearch.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- }
- //</editor-fold>
- /* Create and display the form */
- java.awt.EventQueue.invokeLater(new Runnable() {
- public void run() {
- new filesearch().setVisible(true);
- }
- });
- }
- // Variables declaration - do not modify
- private javax.swing.JButton jButton1;
- private javax.swing.JButton jButton2;
- private javax.swing.JLabel jLabel1;
- private javax.swing.JLabel jLabel2;
- private javax.swing.JScrollPane jScrollPane1;
- private javax.swing.JTextArea jTextArea1;
- private javax.swing.JTextField jTextField1;
- private javax.swing.JTextField jTextField2;
- // End of variables declaration
- }
- Practical No.:6
- Aim: Program to find word and its occurrence inside a file
- Code:
- import java.io.*;
- import javax.swing.*;
- public class wordsearch extends javax.swing.JFrame {
- public wordsearch() {
- initComponents();
- }
- @SuppressWarnings("unchecked")
- // <editor-fold defaultstate="collapsed" desc="Generated Code">
- private void initComponents() {
- jLabel1 = new javax.swing.JLabel();
- jLabel2 = new javax.swing.JLabel();
- jTextField1 = new javax.swing.JTextField();
- jTextField2 = new javax.swing.JTextField();
- jButton1 = new javax.swing.JButton();
- jButton2 = new javax.swing.JButton();
- setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
- jLabel1.setText("Enter the path to the file:");
- jLabel2.setText("Enter the String to find:");
- jButton1.setText("Search");
- jButton1.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jButton1ActionPerformed(evt);
- }
- });
- jButton2.setText("Clear");
- jButton2.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jButton2ActionPerformed(evt);
- }
- });
- javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
- getContentPane().setLayout(layout);
- layout.setHorizontalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addContainerGap()
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addComponent(jLabel1)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(jTextField1))
- .addGroup(layout.createSequentialGroup()
- .addComponent(jLabel2)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
- .addComponent(jTextField2))
- .addGroup(layout.createSequentialGroup()
- .addComponent(jButton1)
- .addGap(18, 18, 18)
- .addComponent(jButton2)
- .addGap(0, 240, Short.MAX_VALUE)))
- .addContainerGap())
- );
- layout.setVerticalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addContainerGap()
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(jLabel1)
- .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addGap(18, 18, 18)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(jLabel2)
- .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addGap(47, 47, 47)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(jButton1)
- .addComponent(jButton2))
- .addContainerGap(26, Short.MAX_VALUE))
- );
- pack();
- }// </editor-fold>
- private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
- BufferedReader br = null;
- try {
- int count = 0, countBuffer = 0, countLine = 0;
- String linenumber = "";
- String filepath = jTextField1.getText();
- String inputsearch = jTextField2.getText();
- String line = "";
- br = new BufferedReader(new FileReader(filepath));
- while ((line = br.readLine()) != null) {
- countLine++;
- String[] words = line.split(" ");
- for (String word : words) {
- if (word.equals(inputsearch)) {
- count++;
- countBuffer++;
- }
- }
- if (countBuffer > 0) {
- countBuffer = 0;
- linenumber += countLine + " ";
- }
- }
- JOptionPane.showMessageDialog(rootPane, "the word " + inputsearch + " has appeared " + count + " times at line number " + linenumber, "Search Result", JOptionPane.INFORMATION_MESSAGE);
- br.close();
- } catch (Exception e) {
- }
- }
- private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
- jTextField1.setText("");
- jTextField2.setText("");
- }
- public static void main(String args[]) {
- //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
- try {
- for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
- if ("Nimbus".equals(info.getName())) {
- javax.swing.UIManager.setLookAndFeel(info.getClassName());
- break;
- }
- }
- } catch (ClassNotFoundException ex) {
- java.util.logging.Logger.getLogger(wordsearch.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (InstantiationException ex) {
- java.util.logging.Logger.getLogger(wordsearch.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (IllegalAccessException ex) {
- java.util.logging.Logger.getLogger(wordsearch.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (javax.swing.UnsupportedLookAndFeelException ex) {
- java.util.logging.Logger.getLogger(wordsearch.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- }
- //</editor-fold>
- /* Create and display the form */
- java.awt.EventQueue.invokeLater(new Runnable() {
- public void run() {
- new wordsearch().setVisible(true);
- }
- });
- }
- // Variables declaration - do not modify
- private javax.swing.JButton jButton1;
- private javax.swing.JButton jButton2;
- private javax.swing.JLabel jLabel1;
- private javax.swing.JLabel jLabel2;
- private javax.swing.JTextField jTextField1;
- private javax.swing.JTextField jTextField2;
- // End of variables declaration
- }
- Output:
- Practical No.: 7.a
- Aim: Use FTK Imager to create image of a computer system
- Code:
- Step1: File-> Create Disk Image
- Step2: Select Contents of a folder option from it and click Next>
- Step3: Click Yes
- Step4: Select a folder you want to create Image and click on Finish
- Step5: Select Destination folder by adding button.
- Step6: Add Case Details and click on next>
- Step7:Add Destination Name AND Image Filename.
- Step 8:Click on Start
- Output:
- Image Summary:
- Practical No.: 7.b
- Aim: Create Server Image
- Code:
- Practical No.: 7.c
- Aim: Create a image of mobile
- Code:
- Note: A ‘Rooted’ device is needed for the process with superuser permissions.
- 1)Allow Usb Debugging in Developer Options in mobile phone for ADB.
- 2)Open Andriller
- 3)Set the output path to the location where the backup is to be taken.
- 4)Connect the device to the computer using a data cable.
- Click on the Check button to connect the mobile device. Serial number of the device is displayed.
- 5)Select the ‘Use AB method(ignore root)’ and ‘Extract Shared Storage’ checkboxes.
- 6)Click on ‘GO!’
- Practical No.:8
- Aim: Practical to perform registry view forensics
- Code:
- Software : ProDiscover
- 1) Computer Forensic
- HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\RecentDocs\
- This key shows the recent documents that were opened.
- 2)Computer Network
- HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\DeviceClasses
- Beneath this key are two other keys of interest:
- {53f56307-b6bf-11d0-94f2-00a0c91efb8b} & {53f5630d-b6bf-11d0-94f2-00a0c91efb8b}
- These are Device Class GUID keys for Disks and Volumes, respectively. Beneath the Disk GUID key are several subkeys that appear as follows (the key name is wrapped):
- ##?#USBSTOR#Disk&Ven_SanDisk&Prod_U3_Cruzer_Micro&Rev_3.27#0000161511737EFB&0
- #{53f56307-b6bf-11d0-94f2-00a0c91efb8b}
- 3) Mobile Device
- View the device interface GUID, Hardware Id, and device class information about your device.
- 1) Find this registry key and note the DeviceInstance value:
- HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\DeviceClasses\
- 2) Find the device instance registry key and get the device interface GUID:
- HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\USB\<hardware id>\<instance id>\Device Parameters
- 3) Under the device instance key, note the device class, subclass, and protocol codes:
- HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\USB
- 4)Wireless Network
- HKLM\SYSTEM\ControlSet001\ Services\Tcpip\Parameters\Interfaces\
- n addition to logging the name of the SSID, Windows also logs the network settings of that particular connection - such as the IP address, DHCP domain, subnet mask, etc.
- Practical No.:9.a
- Aim: Computer system analysis using FTK
- Code:
- Practical No.:9.b
- Aim: Practical to perform network forensic by wired network
- Code:
- 1)Inspect traffic for a specifc IP address.
- This will display all traffic for the IP entered, source or destination.
- IP-: 192.168.2.197
- 2) Sniff the credentials details from the vulnerable website.
- 3)For a Specific IP address search for a specific word in URL.
- Here we searched for mu.ac.in . So we searched "mu" in the filter.
- ¬¬¬-
- 4) Check what user has typed in browser in url
- 5)Check what string user has passed in google search engine.
- Here the victim searched for "computer" keyword.... And so we got computer keyword in info tab.
- 6) Detect DOS attack.
- DOS attacks usually send a lot of traffic to the victim machine to consume its resources so that the legit users are not able to access the services. A very common traditional example is Ping flood as DOS attack.
- Ping flood: Send a huge amount of Ping packets with packet size as big as possible. In windows you can specify the data/buffer size too. The command is ping -l. The attacker will use the maximum value.
- Detection: The normal ping packet has default packet size of 32 bytes in case of Windows. So if you see a lot of Ping packets with unusual size of buffer for eg: like 4000 then you could say it could be a Ping flood. You can use PING command to simulate this attack. In wireshark create a filter for ICMP Echo packets and check the buffer size.
- Source
- Destination
- 7) Find out packets which are getting the response as PAGE NOT FOUND.
- Here we got page not found type website-: trafficindia.com/india.htm and detected in wireshark.
- 8) Find out those packets which are getting response.
- Here we searched for mu.ac.in. We got response. And detected it in Wireshark.
- 9)Find packets according to their length.
- 10) Find Packets-: Browser Specific.
- Its a good idea to understand what user agents are being used on your network, malicious traffic can often use unusual agent strings. To search for a user agent use this filter
- 11)Inspect traffic between specific source and destination
- Source 192.168.2.207 and destination 192.168.2.105
- 12) Find out packet having good checksum value.
- 13) To sniff communication between client and server
- Java code for TcpClient.java
- import java.net.*;
- import java.io.*;
- public class TcpClient
- {
- public staatic void main(Strin args[]) throws Exception
- {
- System.out.println("CLIENT");
- byte b[]=new byte[1000];
- Socket s1=new Siocket("IT_101",9000);
- System.out.println("Server Found");
- InputStream is=s1.getInputStream();
- BufferedReader br=new BufferedReader(new InputStreamReader(is));
- System.out.println(br.readLine());
- OutputStream os=s1.getOutputStream();
- System.in.read(b,0,1000);
- os.write(b);
- }
- }
- Java code for TcpServer.java
- import java.io.*;
- import java.net.*;
- public class TcpServer
- {
- public static void main(String args[]) throws Exception
- {
- OutputStream os;
- System.out.println("SERVER");
- ServerSocket ss = new ServerSocket(9000);
- Socket s1=ss.accept();
- os=s1.getOutputStream();
- byte b[]=new byte[1000];
- System.out.println("Client Connected");
- System.out.println("Enter your message");
- System.in.read(b,0,b.length);
- os.write(b);
- InputStream is=s1.getInputStream();
- BufferedReader br=new BufferedReader(new InputStreamReader(is));
- System.out.println(br.readLine());
- }
- }
- Compiling and running the java server code on server machine
- Compiling and running the java server code on client machine
- Open Wireshark
- In Filter tcp.stream eq 1
- Select ip address 192.168.2.201 and right click,select follow-Tcp Stream
- Practical No.:9.c
- Aim: Practical to perform mobile device forensic(Innovative Practical)
- Software: Magnet Axiom
- Code:
- 1) Enter Case Details
- 2) Acquire Evidence
- 3) Load Evidence
- 4) Analyze Evidence
- 5)Examine Evidence
- 6)Bookmark
- 7)Report Creation
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement