Advertisement
Guest User

Untitled

a guest
Oct 8th, 2018
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 47.99 KB | None | 0 0
  1. Practical No.:1
  2. Aim: Program to take database backup
  3. Code:
  4. import java.io.FileWriter;
  5. import java.sql.Connection;
  6. import java.sql.DriverManager;
  7. public class backup extends javax.swing.JFrame {
  8. public backup() {
  9. initComponents();
  10. }
  11. @SuppressWarnings("unchecked")
  12. // <editor-fold defaultstate="collapsed" desc="Generated Code">
  13. private void initComponents() {
  14. jLabel1 = new javax.swing.JLabel();
  15. jLabel3 = new javax.swing.JLabel();
  16. jLabel9 = new javax.swing.JLabel();
  17. jLabel10 = new javax.swing.JLabel();
  18. jLabel11 = new javax.swing.JLabel();
  19. jLabel12 = new javax.swing.JLabel();
  20. jLabel13 = new javax.swing.JLabel();
  21. jLabel2 = new javax.swing.JLabel();
  22. jTextField1 = new javax.swing.JTextField();
  23. jTextField2 = new javax.swing.JTextField();
  24. jTextField3 = new javax.swing.JTextField();
  25. jTextField4 = new javax.swing.JTextField();
  26. jTextField5 = new javax.swing.JTextField();
  27. jTextField6 = new javax.swing.JTextField();
  28. jButton1 = new javax.swing.JButton();
  29. jButton2 = new javax.swing.JButton();
  30.  
  31. jLabel1.setText("jLabel1");
  32. setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
  33.  
  34. jLabel9.setText("My SQl path:");
  35. jLabel10.setText("My SQL user:");
  36. jLabel11.setText("My SQL password:");
  37. jLabel12.setText("Database name:");
  38. jLabel13.setText("Backup Path:");
  39. jLabel2.setText("Backup file name:");
  40.  
  41. jTextField3.addActionListener(new java.awt.event.ActionListener() {
  42. public void actionPerformed(java.awt.event.ActionEvent evt) {
  43. jTextField3ActionPerformed(evt);
  44. }
  45. });
  46.  
  47. jTextField4.addActionListener(new java.awt.event.ActionListener() {
  48. public void actionPerformed(java.awt.event.ActionEvent evt) {
  49. jTextField4ActionPerformed(evt);
  50. }
  51. });
  52.  
  53. jTextField5.addActionListener(new java.awt.event.ActionListener() {
  54. public void actionPerformed(java.awt.event.ActionEvent evt) {
  55. jTextField5ActionPerformed(evt);
  56. }
  57. });
  58.  
  59. jTextField6.addActionListener(new java.awt.event.ActionListener() {
  60. public void actionPerformed(java.awt.event.ActionEvent evt) {
  61. jTextField6ActionPerformed(evt);
  62. }
  63. });
  64.  
  65. jButton1.setText("Backup");
  66. jButton1.addActionListener(new java.awt.event.ActionListener() {
  67. public void actionPerformed(java.awt.event.ActionEvent evt) {
  68. jButton1ActionPerformed(evt);
  69. }
  70. });
  71.  
  72. jButton2.setText("Clear");
  73. jButton2.addActionListener(new java.awt.event.ActionListener() {
  74. public void actionPerformed(java.awt.event.ActionEvent evt) {
  75. jButton2ActionPerformed(evt);
  76. }
  77. });
  78.  
  79. javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
  80. getContentPane().setLayout(layout);
  81. layout.setHorizontalGroup(
  82. layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  83. .addGroup(layout.createSequentialGroup()
  84. .addContainerGap()
  85. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  86. .addGroup(layout.createSequentialGroup()
  87. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  88. .addGroup(layout.createSequentialGroup()
  89. .addComponent(jLabel11)
  90. .addGap(18, 18, 18)
  91. .addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, 468, javax.swing.GroupLayout.PREFERRED_SIZE))
  92. .addGroup(layout.createSequentialGroup()
  93. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  94. .addComponent(jLabel10)
  95. .addComponent(jLabel9)
  96. .addComponent(jLabel12))
  97. .addGap(28, 28, 28)
  98. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
  99. .addComponent(jTextField2)
  100. .addComponent(jTextField1)
  101. .addComponent(jTextField5, javax.swing.GroupLayout.DEFAULT_SIZE, 468, Short.MAX_VALUE)
  102. .addComponent(jTextField4))
  103. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 123, Short.MAX_VALUE)
  104. .addComponent(jLabel3)))
  105. .addContainerGap(130, Short.MAX_VALUE))
  106. .addGroup(layout.createSequentialGroup()
  107. .addComponent(jLabel13)
  108. .addContainerGap())
  109. .addGroup(layout.createSequentialGroup()
  110. .addComponent(jLabel2)
  111. .addGap(18, 18, 18)
  112. .addComponent(jTextField6, javax.swing.GroupLayout.PREFERRED_SIZE, 468, javax.swing.GroupLayout.PREFERRED_SIZE)
  113. .addGap(0, 0, Short.MAX_VALUE))))
  114. .addGroup(layout.createSequentialGroup()
  115. .addGap(54, 54, 54)
  116. .addComponent(jButton1)
  117. .addGap(242, 242, 242)
  118. .addComponent(jButton2)
  119. .addGap(0, 0, Short.MAX_VALUE))
  120. );
  121. layout.setVerticalGroup(
  122. layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  123. .addGroup(layout.createSequentialGroup()
  124. .addGap(0, 0, Short.MAX_VALUE)
  125. .addComponent(jLabel3)
  126. .addGap(163, 163, 163))
  127. .addGroup(layout.createSequentialGroup()
  128. .addContainerGap()
  129. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  130. .addComponent(jLabel9)
  131. .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
  132. .addGap(18, 18, 18)
  133. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  134. .addComponent(jLabel10)
  135. .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
  136. .addGap(18, 18, 18)
  137. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  138. .addComponent(jLabel11)
  139. .addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
  140. .addGap(18, 18, 18)
  141. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  142. .addComponent(jTextField4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  143. .addComponent(jLabel12))
  144. .addGap(18, 18, 18)
  145. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  146. .addComponent(jLabel13)
  147. .addComponent(jTextField5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
  148. .addGap(18, 18, 18)
  149. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  150. .addComponent(jLabel2)
  151. .addComponent(jTextField6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
  152. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 31, Short.MAX_VALUE)
  153. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  154. .addComponent(jButton1)
  155. .addComponent(jButton2))
  156. .addGap(23, 23, 23))
  157. );
  158. pack();
  159. }// </editor-fold>
  160. private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
  161. try {
  162. Class.forName("com.mysql.jdbc.Driver");
  163. Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/"+jTextField4.getText(),jTextField2.getText(),jTextField3.getText());
  164. FileWriter fos = new FileWriter( jTextField5.getText()+"\\mycmd.bat");
  165. String cmd = "set path =%path%;" + jTextField1.getText() + ";+\n";
  166. cmd+= "mysqldump -u" + jTextField2.getText() + " -p" + jTextField3.getText() + "" + jTextField4.getText()+">"+ jTextField5.getText()+"\\"+jTextField6.getText();
  167. fos.write(cmd);
  168. fos.close();
  169. Runtime rt = Runtime.getRuntime();
  170. rt.exec("cmd.exe /c start"+jTextField5.getText()+"\\mycmd.bat");
  171. System.out.println("Backup completed successfully");
  172. } catch (Exception e) {
  173. e.printStackTrace();
  174. }
  175. }
  176.  
  177. private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
  178. jTextField1.setText(null);
  179. jTextField2.setText(null);
  180. jTextField3.setText(null);
  181. jTextField4.setText(null);
  182. jTextField5.setText(null);
  183. jTextField6.setText(null);
  184. }
  185.  
  186. /**
  187. * @param args the command line arguments
  188. */
  189. public static void main(String args[]) {
  190. /* Set the Nimbus look and feel */
  191. //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
  192. /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
  193. * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
  194. */
  195. try {
  196. for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
  197. if ("Nimbus".equals(info.getName())) {
  198. javax.swing.UIManager.setLookAndFeel(info.getClassName());
  199. break;
  200. }
  201. }
  202. } catch (ClassNotFoundException ex) {
  203. java.util.logging.Logger.getLogger(backup.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  204. } catch (InstantiationException ex) {
  205. java.util.logging.Logger.getLogger(backup.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  206. } catch (IllegalAccessException ex) {
  207. java.util.logging.Logger.getLogger(backup.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  208. } catch (javax.swing.UnsupportedLookAndFeelException ex) {
  209. java.util.logging.Logger.getLogger(backup.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  210. }
  211. //</editor-fold>
  212.  
  213. /* Create and display the form */
  214. java.awt.EventQueue.invokeLater(new Runnable() {
  215. public void run() {
  216. new backup().setVisible(true);
  217. }
  218. });
  219. }
  220.  
  221. // Variables declaration - do not modify
  222. private javax.swing.JButton jButton1;
  223. private javax.swing.JButton jButton2;
  224. private javax.swing.JLabel jLabel1;
  225. private javax.swing.JLabel jLabel10;
  226. private javax.swing.JLabel jLabel11;
  227. private javax.swing.JLabel jLabel12;
  228. private javax.swing.JLabel jLabel13;
  229. private javax.swing.JLabel jLabel2;
  230. private javax.swing.JLabel jLabel3;
  231. private javax.swing.JLabel jLabel9;
  232. private javax.swing.JTextField jTextField1;
  233. private javax.swing.JTextField jTextField2;
  234. private javax.swing.JTextField jTextField3;
  235. private javax.swing.JTextField jTextField4;
  236. private javax.swing.JTextField jTextField5;
  237. private javax.swing.JTextField jTextField6;
  238. // End of variables declaration
  239. }
  240. Output:
  241.  
  242.  
  243.  
  244.  
  245.  
  246.  
  247. Practical No.:2
  248. Aim: Program to restore database
  249. Code:
  250. import java.io.FileWriter;
  251. import java.sql.*;
  252. import java.util.logging.Level;
  253. import java.util.logging.Logger;
  254.  
  255. public class MySQLRestore extends javax.swing.JFrame {
  256.  
  257. public MySQLRestore() {
  258. initComponents();
  259. }
  260. @SuppressWarnings("unchecked")
  261. // <editor-fold defaultstate="collapsed" desc="Generated Code">
  262. private void initComponents() {
  263.  
  264. jLabel1 = new javax.swing.JLabel();
  265. jLabel2 = new javax.swing.JLabel();
  266. jLabel3 = new javax.swing.JLabel();
  267. jLabel4 = new javax.swing.JLabel();
  268. jLabel5 = new javax.swing.JLabel();
  269. jLabel6 = new javax.swing.JLabel();
  270. jButton1 = new javax.swing.JButton();
  271. mysqlpath = new javax.swing.JTextField();
  272. mysqluser = new javax.swing.JTextField();
  273. mysqlpass = new javax.swing.JTextField();
  274. dbname = new javax.swing.JTextField();
  275. backuppath = new javax.swing.JTextField();
  276. filename = new javax.swing.JTextField();
  277. jButton2 = new javax.swing.JButton();
  278.  
  279. setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
  280. setTitle("MySQL Restore");
  281.  
  282. jLabel1.setText("MySQL Path :");
  283. jLabel2.setText("MySQL User :");
  284. jLabel3.setText("MySQL Password:");
  285. jLabel4.setText("Database Name :");
  286. jLabel5.setText("Backup Path :");
  287.  
  288. jLabel6.setText("Backup File Name :");
  289.  
  290. jButton1.setText("Restore");
  291. jButton1.addActionListener(new java.awt.event.ActionListener() {
  292. public void actionPerformed(java.awt.event.ActionEvent evt) {
  293. jButton1ActionPerformed(evt);
  294. }
  295. });
  296.  
  297. mysqlpath.addActionListener(new java.awt.event.ActionListener() {
  298. public void actionPerformed(java.awt.event.ActionEvent evt) {
  299. mysqlpathActionPerformed(evt);
  300. }
  301. });
  302.  
  303. mysqluser.addActionListener(new java.awt.event.ActionListener() {
  304. public void actionPerformed(java.awt.event.ActionEvent evt) {
  305. mysqluserActionPerformed(evt);
  306. }
  307. });
  308.  
  309. jButton2.setText("Clear");
  310. jButton2.addActionListener(new java.awt.event.ActionListener() {
  311. public void actionPerformed(java.awt.event.ActionEvent evt) {
  312. jButton2ActionPerformed(evt);
  313. }
  314. });
  315.  
  316. javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
  317. getContentPane().setLayout(layout);
  318. layout.setHorizontalGroup(
  319. layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  320. .addGroup(layout.createSequentialGroup()
  321. .addContainerGap()
  322. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
  323. .addGroup(layout.createSequentialGroup()
  324. .addComponent(jLabel1)
  325. .addGap(2, 2, 2)
  326. .addComponent(mysqlpath, javax.swing.GroupLayout.PREFERRED_SIZE, 226, javax.swing.GroupLayout.PREFERRED_SIZE))
  327. .addGroup(layout.createSequentialGroup()
  328. .addComponent(jLabel2)
  329. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  330. .addComponent(mysqluser))
  331. .addGroup(layout.createSequentialGroup()
  332. .addComponent(jLabel3)
  333. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  334. .addComponent(mysqlpass))
  335. .addGroup(layout.createSequentialGroup()
  336. .addComponent(jLabel4)
  337. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  338. .addComponent(dbname))
  339. .addGroup(layout.createSequentialGroup()
  340. .addComponent(jLabel5)
  341. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  342. .addComponent(backuppath))
  343. .addGroup(layout.createSequentialGroup()
  344. .addComponent(jLabel6)
  345. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  346. .addComponent(filename))
  347. .addGroup(layout.createSequentialGroup()
  348. .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 161, javax.swing.GroupLayout.PREFERRED_SIZE)
  349. .addGap(18, 18, 18)
  350. .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 165, javax.swing.GroupLayout.PREFERRED_SIZE)))
  351. .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
  352. );
  353. layout.setVerticalGroup(
  354. layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  355. .addGroup(layout.createSequentialGroup()
  356. .addContainerGap()
  357. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  358. .addComponent(jLabel1)
  359. .addComponent(mysqlpath, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
  360. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
  361. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  362. .addComponent(jLabel2)
  363. .addComponent(mysqluser, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
  364. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
  365. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  366. .addComponent(jLabel3)
  367. .addComponent(mysqlpass, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
  368. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
  369. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  370. .addComponent(jLabel4)
  371. .addComponent(dbname, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
  372. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
  373. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  374. .addComponent(jLabel5)
  375. .addComponent(backuppath, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
  376. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
  377. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  378. .addComponent(jLabel6)
  379. .addComponent(filename, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
  380. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
  381. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  382. .addComponent(jButton1)
  383. .addComponent(jButton2))
  384. .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
  385. );
  386.  
  387. pack();
  388. }// </editor-fold>
  389.  
  390. private void mysqlpathActionPerformed(java.awt.event.ActionEvent evt) {
  391. // TODO add your handling code here:
  392. }
  393.  
  394. private void mysqluserActionPerformed(java.awt.event.ActionEvent evt) {
  395. // TODO add your handling code here:
  396. }
  397.  
  398. private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
  399.  
  400. String db=dbname.getText();
  401. String user=mysqluser.getText();
  402. String pass=mysqlpass.getText();
  403. String backupPath=backuppath.getText();
  404. String path=mysqlpath.getText();
  405. String fname=filename.getText();
  406. try {
  407. Class.forName("com.mysql.jdbc.Driver");
  408. Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/"+db,user,pass);
  409. FileWriter fos=new FileWriter(backupPath+"\\mycmd.bat");
  410. String cmd="set path=%path%;"+path+";\n";
  411. cmd+="mysql -u"+user+ " -p"+pass+" "+db+"<"+ backupPath+"\\"+fname;
  412. fos.write(cmd);
  413. fos.close();
  414. Runtime rt=Runtime.getRuntime();
  415. rt.exec("cmd.exe /c start "+backupPath+"\\mycmd.bat");
  416. System.out.println("Restore completed Successfully.");
  417.  
  418. } catch (Exception ex) {
  419. Logger.getLogger(MySQLBackup.class.getName()).log(Level.SEVERE, null, ex);
  420. }
  421. }
  422.  
  423. private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
  424. // TODO add your handling code here:
  425. mysqlpath.setText("");
  426. mysqluser.setText("");
  427. mysqlpass.setText("");
  428. dbname.setText("");
  429. backuppath.setText("");
  430. filename.setText("");
  431. }
  432. public static void main(String args[]) {
  433. /* Set the Nimbus look and feel */
  434. //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
  435.  
  436. try {
  437. for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
  438. if ("Nimbus".equals(info.getName())) {
  439. javax.swing.UIManager.setLookAndFeel(info.getClassName());
  440. break;
  441. }
  442. }
  443. } catch (ClassNotFoundException ex) {
  444. java.util.logging.Logger.getLogger(MySQLBackup.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  445. } catch (InstantiationException ex) {
  446. java.util.logging.Logger.getLogger(MySQLBackup.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  447. } catch (IllegalAccessException ex) {
  448. java.util.logging.Logger.getLogger(MySQLBackup.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  449. } catch (javax.swing.UnsupportedLookAndFeelException ex) {
  450. java.util.logging.Logger.getLogger(MySQLBackup.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  451. }
  452. //</editor-fold>
  453.  
  454. /* Create and display the form */
  455. java.awt.EventQueue.invokeLater(new Runnable() {
  456. public void run() {
  457. new MySQLRestore().setVisible(true);
  458. }
  459. });
  460. }
  461. // Variables declaration - do not modify
  462. private javax.swing.JTextField backuppath;
  463. private javax.swing.JTextField dbname;
  464. private javax.swing.JTextField filename;
  465. private javax.swing.JButton jButton1;
  466. private javax.swing.JButton jButton2;
  467. private javax.swing.JLabel jLabel1;
  468. private javax.swing.JLabel jLabel2;
  469. private javax.swing.JLabel jLabel3;
  470. private javax.swing.JLabel jLabel4;
  471. private javax.swing.JLabel jLabel5;
  472. private javax.swing.JLabel jLabel6;
  473. private javax.swing.JTextField mysqlpass;
  474. private javax.swing.JTextField mysqlpath;
  475. private javax.swing.JTextField mysqluser;
  476. // End of variables declaration
  477. }
  478. Output :
  479.  
  480.  
  481.  
  482.  
  483.  
  484.  
  485.  
  486.  
  487.  
  488.  
  489.  
  490.  
  491.  
  492.  
  493.  
  494.  
  495.  
  496.  
  497.  
  498. Practical No.: 3
  499. Aim: Use of driveImageXml to take backup and restore data
  500. Code:
  501. Steps for Backup:
  502. 1. Choose drive to take Backup.
  503.  
  504. 2. Open DriveImage XML software and select target drive.
  505.  
  506.  
  507. 3. Rename backup file name if needed.
  508.  
  509.  
  510.  
  511.  
  512. 4. Below is the files generated after backup.
  513.  
  514.  
  515. Steps for Recovery of Drive :
  516. Here we are deleting all the contents of drive and then restoring the same.
  517.  
  518. 1. Click Restore option in DriveImage XML software and select target Disk.
  519.  
  520.  
  521. 2. Select the backup file path and click next.
  522.  
  523.  
  524.  
  525. 3. Then select targeted drive and click next.
  526.  
  527.  
  528.  
  529.  
  530.  
  531.  
  532. 4. Enter Disk name in the dialog box and click Ok.
  533.  
  534.  
  535.  
  536. Drive contents has been restored.
  537.  
  538.  
  539.  
  540.  
  541.  
  542.  
  543.  
  544.  
  545.  
  546.  
  547.  
  548.  
  549.  
  550.  
  551.  
  552.  
  553.  
  554.  
  555.  
  556.  
  557.  
  558.  
  559.  
  560.  
  561.  
  562. Practical No.: 4
  563. Aim: Write a program to log files
  564. Code:
  565. import java.io.FileWriter;
  566. class createlog
  567. {
  568. public static void main(String s[])
  569. {
  570. try
  571. {
  572. String cmd="WMIC /OUTPUT:D:\\LIST2.html PROCESS get name,processid,creationdate /format:hform";
  573. FileWriter fos=new FileWriter("D:\\mycmd.bat");
  574. fos.write(cmd);
  575. fos.close();
  576. Runtime rt=Runtime.getRuntime();
  577. rt.exec("cmd.exe /c start D:\\mycmd.bat");
  578. }
  579. catch(Exception e)
  580. {
  581. e.printStackTrace();
  582. }
  583. }
  584. }
  585.  
  586. Output:
  587.  
  588.  
  589.  
  590.  
  591.  
  592.  
  593.  
  594.  
  595.  
  596.  
  597.  
  598.  
  599.  
  600.  
  601.  
  602.  
  603.  
  604.  
  605.  
  606.  
  607.  
  608.  
  609.  
  610.  
  611.  
  612.  
  613.  
  614.  
  615.  
  616.  
  617.  
  618.  
  619. Practical No.: 5
  620. Aim: Program to display filepath in directory
  621. Code:
  622. import java.io.File;
  623. import java.util.ArrayList;
  624. public class filesearch extends javax.swing.JFrame {
  625. String fileName;
  626. File dir;
  627. public filesearch() {
  628. initComponents();
  629. }
  630. @SuppressWarnings("unchecked")
  631. // <editor-fold defaultstate="collapsed" desc="Generated Code">
  632. private void initComponents() {
  633.  
  634. jLabel1 = new javax.swing.JLabel();
  635. jLabel2 = new javax.swing.JLabel();
  636. jTextField1 = new javax.swing.JTextField();
  637. jTextField2 = new javax.swing.JTextField();
  638. jButton1 = new javax.swing.JButton();
  639. jButton2 = new javax.swing.JButton();
  640. jScrollPane1 = new javax.swing.JScrollPane();
  641. jTextArea1 = new javax.swing.JTextArea();
  642.  
  643. setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
  644.  
  645. jLabel1.setText("Enter directory to be searched");
  646.  
  647. jLabel2.setText("Enter file to be searched");
  648.  
  649. jButton1.setText("Search");
  650. jButton1.addActionListener(new java.awt.event.ActionListener() {
  651. public void actionPerformed(java.awt.event.ActionEvent evt) {
  652. jButton1ActionPerformed(evt);
  653. }
  654. });
  655.  
  656. jButton2.setText("Clear");
  657. jButton2.addActionListener(new java.awt.event.ActionListener() {
  658. public void actionPerformed(java.awt.event.ActionEvent evt) {
  659. jButton2ActionPerformed(evt);
  660. }
  661. });
  662.  
  663. jTextArea1.setColumns(20);
  664. jTextArea1.setRows(5);
  665. jScrollPane1.setViewportView(jTextArea1);
  666.  
  667. javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
  668. getContentPane().setLayout(layout);
  669. layout.setHorizontalGroup(
  670. layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  671. .addGroup(layout.createSequentialGroup()
  672. .addContainerGap()
  673. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  674. .addComponent(jScrollPane1)
  675. .addGroup(layout.createSequentialGroup()
  676. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  677. .addComponent(jLabel1)
  678. .addComponent(jLabel2))
  679. .addGap(18, 18, 18)
  680. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  681. .addComponent(jTextField1)
  682. .addComponent(jTextField2, javax.swing.GroupLayout.DEFAULT_SIZE, 215, Short.MAX_VALUE)))
  683. .addGroup(layout.createSequentialGroup()
  684. .addComponent(jButton1)
  685. .addGap(27, 27, 27)
  686. .addComponent(jButton2)
  687. .addGap(0, 0, Short.MAX_VALUE)))
  688. .addContainerGap())
  689. );
  690. layout.setVerticalGroup(
  691. layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  692. .addGroup(layout.createSequentialGroup()
  693. .addContainerGap()
  694. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  695. .addComponent(jLabel1)
  696. .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
  697. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  698. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  699. .addComponent(jLabel2)
  700. .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
  701. .addGap(42, 42, 42)
  702. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  703. .addComponent(jButton1)
  704. .addComponent(jButton2))
  705. .addGap(18, 18, 18)
  706. .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 132, javax.swing.GroupLayout.PREFERRED_SIZE)
  707. .addContainerGap(28, Short.MAX_VALUE))
  708. );
  709.  
  710. pack();
  711. }// </editor-fold>
  712.  
  713. private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
  714. jTextArea1.setText("");
  715. dir = new File(jTextField1.getText());
  716. search(dir);
  717.  
  718. }
  719.  
  720. private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
  721. jTextField1.setText("");
  722. jTextField2.setText("");
  723. jTextArea1.setText("");
  724. }
  725. public void search(File file) {
  726. fileName = jTextField2.getText();
  727. if (file.isDirectory()) {
  728. for (File temp : file.listFiles()) {
  729. if (temp.isDirectory()) {
  730. search(temp);
  731. } else {
  732. if (fileName.equals(temp.getName().toLowerCase())) {
  733. jTextArea1.append(temp.getAbsoluteFile().toString() + "\n");
  734. }
  735. }
  736. }
  737. } else {
  738. System.out.println(file.getAbsoluteFile() + "Permission denied");
  739. }
  740. }
  741.  
  742. /**
  743. * @param args the command line arguments
  744. */
  745. public static void main(String args[]) {
  746. /* Set the Nimbus look and feel */
  747. //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
  748. /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
  749. * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
  750. */
  751. try {
  752. for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
  753. if ("Nimbus".equals(info.getName())) {
  754. javax.swing.UIManager.setLookAndFeel(info.getClassName());
  755. break;
  756. }
  757. }
  758. } catch (ClassNotFoundException ex) {
  759. java.util.logging.Logger.getLogger(filesearch.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  760. } catch (InstantiationException ex) {
  761. java.util.logging.Logger.getLogger(filesearch.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  762. } catch (IllegalAccessException ex) {
  763. java.util.logging.Logger.getLogger(filesearch.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  764. } catch (javax.swing.UnsupportedLookAndFeelException ex) {
  765. java.util.logging.Logger.getLogger(filesearch.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  766. }
  767. //</editor-fold>
  768.  
  769. /* Create and display the form */
  770. java.awt.EventQueue.invokeLater(new Runnable() {
  771. public void run() {
  772. new filesearch().setVisible(true);
  773. }
  774. });
  775. }
  776.  
  777. // Variables declaration - do not modify
  778. private javax.swing.JButton jButton1;
  779. private javax.swing.JButton jButton2;
  780. private javax.swing.JLabel jLabel1;
  781. private javax.swing.JLabel jLabel2;
  782. private javax.swing.JScrollPane jScrollPane1;
  783. private javax.swing.JTextArea jTextArea1;
  784. private javax.swing.JTextField jTextField1;
  785. private javax.swing.JTextField jTextField2;
  786. // End of variables declaration
  787. }
  788.  
  789.  
  790.  
  791.  
  792.  
  793.  
  794.  
  795.  
  796.  
  797.  
  798.  
  799.  
  800.  
  801.  
  802. Practical No.:6
  803. Aim: Program to find word and its occurrence inside a file
  804. Code:
  805. import java.io.*;
  806. import javax.swing.*;
  807. public class wordsearch extends javax.swing.JFrame {
  808. public wordsearch() {
  809. initComponents();
  810. }
  811. @SuppressWarnings("unchecked")
  812. // <editor-fold defaultstate="collapsed" desc="Generated Code">
  813. private void initComponents() {
  814. jLabel1 = new javax.swing.JLabel();
  815. jLabel2 = new javax.swing.JLabel();
  816. jTextField1 = new javax.swing.JTextField();
  817. jTextField2 = new javax.swing.JTextField();
  818. jButton1 = new javax.swing.JButton();
  819. jButton2 = new javax.swing.JButton();
  820. setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
  821. jLabel1.setText("Enter the path to the file:");
  822. jLabel2.setText("Enter the String to find:");
  823. jButton1.setText("Search");
  824. jButton1.addActionListener(new java.awt.event.ActionListener() {
  825. public void actionPerformed(java.awt.event.ActionEvent evt) {
  826. jButton1ActionPerformed(evt);
  827. }
  828. });
  829. jButton2.setText("Clear");
  830. jButton2.addActionListener(new java.awt.event.ActionListener() {
  831. public void actionPerformed(java.awt.event.ActionEvent evt) {
  832. jButton2ActionPerformed(evt);
  833. }
  834. });
  835. javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
  836. getContentPane().setLayout(layout);
  837. layout.setHorizontalGroup(
  838. layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  839. .addGroup(layout.createSequentialGroup()
  840. .addContainerGap()
  841. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  842. .addGroup(layout.createSequentialGroup()
  843. .addComponent(jLabel1)
  844. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  845. .addComponent(jTextField1))
  846. .addGroup(layout.createSequentialGroup()
  847. .addComponent(jLabel2)
  848. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
  849. .addComponent(jTextField2))
  850. .addGroup(layout.createSequentialGroup()
  851. .addComponent(jButton1)
  852. .addGap(18, 18, 18)
  853. .addComponent(jButton2)
  854. .addGap(0, 240, Short.MAX_VALUE)))
  855. .addContainerGap())
  856. );
  857. layout.setVerticalGroup(
  858. layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  859. .addGroup(layout.createSequentialGroup()
  860. .addContainerGap()
  861. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  862. .addComponent(jLabel1)
  863. .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
  864. .addGap(18, 18, 18)
  865. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  866. .addComponent(jLabel2)
  867. .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
  868. .addGap(47, 47, 47)
  869. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  870. .addComponent(jButton1)
  871. .addComponent(jButton2))
  872. .addContainerGap(26, Short.MAX_VALUE))
  873. );
  874.  
  875. pack();
  876. }// </editor-fold>
  877.  
  878. private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
  879. BufferedReader br = null;
  880. try {
  881. int count = 0, countBuffer = 0, countLine = 0;
  882. String linenumber = "";
  883. String filepath = jTextField1.getText();
  884. String inputsearch = jTextField2.getText();
  885. String line = "";
  886. br = new BufferedReader(new FileReader(filepath));
  887. while ((line = br.readLine()) != null) {
  888. countLine++;
  889. String[] words = line.split(" ");
  890. for (String word : words) {
  891. if (word.equals(inputsearch)) {
  892. count++;
  893. countBuffer++;
  894. }
  895. }
  896. if (countBuffer > 0) {
  897. countBuffer = 0;
  898. linenumber += countLine + " ";
  899. }
  900. }
  901. JOptionPane.showMessageDialog(rootPane, "the word " + inputsearch + " has appeared " + count + " times at line number " + linenumber, "Search Result", JOptionPane.INFORMATION_MESSAGE);
  902. br.close();
  903. } catch (Exception e) {
  904. }
  905. }
  906. private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
  907. jTextField1.setText("");
  908. jTextField2.setText("");
  909. }
  910. public static void main(String args[]) {
  911. //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
  912. try {
  913. for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
  914. if ("Nimbus".equals(info.getName())) {
  915. javax.swing.UIManager.setLookAndFeel(info.getClassName());
  916. break;
  917. }
  918. }
  919. } catch (ClassNotFoundException ex) {
  920. java.util.logging.Logger.getLogger(wordsearch.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  921. } catch (InstantiationException ex) {
  922. java.util.logging.Logger.getLogger(wordsearch.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  923. } catch (IllegalAccessException ex) {
  924. java.util.logging.Logger.getLogger(wordsearch.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  925. } catch (javax.swing.UnsupportedLookAndFeelException ex) {
  926. java.util.logging.Logger.getLogger(wordsearch.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  927. }
  928. //</editor-fold>
  929.  
  930. /* Create and display the form */
  931. java.awt.EventQueue.invokeLater(new Runnable() {
  932. public void run() {
  933. new wordsearch().setVisible(true);
  934. }
  935. });
  936. }
  937.  
  938. // Variables declaration - do not modify
  939. private javax.swing.JButton jButton1;
  940. private javax.swing.JButton jButton2;
  941. private javax.swing.JLabel jLabel1;
  942. private javax.swing.JLabel jLabel2;
  943. private javax.swing.JTextField jTextField1;
  944. private javax.swing.JTextField jTextField2;
  945. // End of variables declaration
  946. }
  947. Output:
  948.  
  949.  
  950.  
  951.  
  952. Practical No.: 7.a
  953. Aim: Use FTK Imager to create image of a computer system
  954. Code:
  955. Step1: File-> Create Disk Image
  956.  
  957. Step2: Select Contents of a folder option from it and click Next>
  958.  
  959. Step3: Click Yes
  960.  
  961. Step4: Select a folder you want to create Image and click on Finish
  962.  
  963. Step5: Select Destination folder by adding button.
  964.  
  965. Step6: Add Case Details and click on next>
  966.  
  967. Step7:Add Destination Name AND Image Filename.
  968.  
  969. Step 8:Click on Start
  970.  
  971. Output:
  972.  
  973.  
  974.  
  975. Image Summary:
  976.  
  977.  
  978.  
  979.  
  980.  
  981.  
  982.  
  983.  
  984.  
  985.  
  986.  
  987.  
  988.  
  989.  
  990.  
  991.  
  992.  
  993.  
  994.  
  995.  
  996.  
  997. Practical No.: 7.b
  998. Aim: Create Server Image
  999. Code:
  1000.  
  1001.  
  1002.  
  1003.  
  1004.  
  1005.  
  1006.  
  1007.  
  1008.  
  1009.  
  1010.  
  1011.  
  1012.  
  1013.  
  1014.  
  1015.  
  1016.  
  1017.  
  1018.  
  1019.  
  1020.  
  1021.  
  1022.  
  1023.  
  1024.  
  1025.  
  1026.  
  1027.  
  1028.  
  1029.  
  1030.  
  1031.  
  1032.  
  1033.  
  1034.  
  1035.  
  1036.  
  1037. Practical No.: 7.c
  1038. Aim: Create a image of mobile
  1039. Code:
  1040. Note: A ‘Rooted’ device is needed for the process with superuser permissions.
  1041. 1)Allow Usb Debugging in Developer Options in mobile phone for ADB.
  1042. 2)Open Andriller
  1043.  
  1044.  
  1045. 3)Set the output path to the location where the backup is to be taken.
  1046.  
  1047.  
  1048. 4)Connect the device to the computer using a data cable.
  1049. Click on the Check button to connect the mobile device. Serial number of the device is displayed.
  1050.  
  1051.  
  1052. 5)Select the ‘Use AB method(ignore root)’ and ‘Extract Shared Storage’ checkboxes.
  1053.  
  1054.  
  1055. 6)Click on ‘GO!’
  1056.  
  1057.  
  1058.  
  1059.  
  1060.  
  1061.  
  1062.  
  1063.  
  1064.  
  1065.  
  1066.  
  1067.  
  1068.  
  1069.  
  1070.  
  1071.  
  1072.  
  1073.  
  1074.  
  1075.  
  1076.  
  1077.  
  1078.  
  1079.  
  1080.  
  1081.  
  1082.  
  1083.  
  1084.  
  1085. Practical No.:8
  1086. Aim: Practical to perform registry view forensics
  1087. Code:
  1088. Software : ProDiscover
  1089.  
  1090.  
  1091.  
  1092.  
  1093.  
  1094.  
  1095.  
  1096.  
  1097. 1) Computer Forensic
  1098. HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\RecentDocs\
  1099. This key shows the recent documents that were opened.
  1100.  
  1101.  
  1102. 2)Computer Network
  1103. HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\DeviceClasses
  1104.  
  1105. Beneath this key are two other keys of interest:
  1106.  
  1107. {53f56307-b6bf-11d0-94f2-00a0c91efb8b} & {53f5630d-b6bf-11d0-94f2-00a0c91efb8b}
  1108.  
  1109. 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):
  1110.  
  1111. ##?#USBSTOR#Disk&Ven_SanDisk&Prod_U3_Cruzer_Micro&Rev_3.27#0000161511737EFB&0
  1112. #{53f56307-b6bf-11d0-94f2-00a0c91efb8b}
  1113.  
  1114.  
  1115.  
  1116.  
  1117. 3) Mobile Device
  1118. View the device interface GUID, Hardware Id, and device class information about your device.
  1119.  
  1120. 1) Find this registry key and note the DeviceInstance value:
  1121.  
  1122. HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\DeviceClasses\
  1123.  
  1124. 2) Find the device instance registry key and get the device interface GUID:
  1125. HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\USB\<hardware id>\<instance id>\Device Parameters
  1126.  
  1127. 3) Under the device instance key, note the device class, subclass, and protocol codes:
  1128.  
  1129. HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\USB
  1130.  
  1131.  
  1132. 4)Wireless Network
  1133. HKLM\SYSTEM\ControlSet001\ Services\Tcpip\Parameters\Interfaces\
  1134.  
  1135. 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.
  1136.  
  1137.  
  1138.  
  1139.  
  1140. Practical No.:9.a
  1141. Aim: Computer system analysis using FTK
  1142. Code:
  1143.  
  1144.  
  1145.  
  1146.  
  1147.  
  1148.  
  1149.  
  1150.  
  1151.  
  1152.  
  1153.  
  1154.  
  1155.  
  1156.  
  1157.  
  1158.  
  1159.  
  1160.  
  1161.  
  1162.  
  1163.  
  1164.  
  1165.  
  1166.  
  1167.  
  1168.  
  1169.  
  1170.  
  1171.  
  1172.  
  1173.  
  1174.  
  1175.  
  1176.  
  1177.  
  1178.  
  1179.  
  1180.  
  1181.  
  1182.  
  1183.  
  1184.  
  1185.  
  1186.  
  1187.  
  1188.  
  1189.  
  1190.  
  1191.  
  1192.  
  1193.  
  1194.  
  1195.  
  1196.  
  1197.  
  1198.  
  1199.  
  1200.  
  1201.  
  1202.  
  1203.  
  1204.  
  1205.  
  1206.  
  1207.  
  1208.  
  1209.  
  1210.  
  1211.  
  1212.  
  1213.  
  1214.  
  1215.  
  1216.  
  1217.  
  1218.  
  1219.  
  1220.  
  1221.  
  1222.  
  1223.  
  1224.  
  1225.  
  1226.  
  1227.  
  1228.  
  1229.  
  1230.  
  1231.  
  1232.  
  1233.  
  1234.  
  1235.  
  1236.  
  1237.  
  1238.  
  1239.  
  1240.  
  1241.  
  1242.  
  1243.  
  1244.  
  1245.  
  1246.  
  1247.  
  1248.  
  1249.  
  1250.  
  1251.  
  1252.  
  1253.  
  1254.  
  1255.  
  1256.  
  1257.  
  1258.  
  1259.  
  1260.  
  1261.  
  1262.  
  1263. Practical No.:9.b
  1264. Aim: Practical to perform network forensic by wired network
  1265. Code:
  1266. 1)Inspect traffic for a specifc IP address.
  1267. This will display all traffic for the IP entered, source or destination.
  1268. IP-: 192.168.2.197
  1269.  
  1270.  
  1271.  
  1272. 2) Sniff the credentials details from the vulnerable website.
  1273.  
  1274.  
  1275.  
  1276.  
  1277.  
  1278.  
  1279. 3)For a Specific IP address search for a specific word in URL.
  1280. Here we searched for mu.ac.in . So we searched "mu" in the filter.
  1281.  
  1282. ¬¬¬-
  1283.  
  1284. 4) Check what user has typed in browser in url
  1285.  
  1286.  
  1287. 5)Check what string user has passed in google search engine.
  1288. Here the victim searched for "computer" keyword.... And so we got computer keyword in info tab.
  1289.  
  1290. 6) Detect DOS attack.
  1291. 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.
  1292. 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.
  1293. 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.
  1294.  
  1295.  
  1296.  
  1297.  
  1298. Source
  1299.  
  1300.  
  1301. Destination
  1302.  
  1303. 7) Find out packets which are getting the response as PAGE NOT FOUND.
  1304. Here we got page not found type website-: trafficindia.com/india.htm and detected in wireshark.
  1305.  
  1306.  
  1307.  
  1308.  
  1309. 8) Find out those packets which are getting response.
  1310. Here we searched for mu.ac.in. We got response. And detected it in Wireshark.
  1311.  
  1312.  
  1313. 9)Find packets according to their length.
  1314.  
  1315.  
  1316.  
  1317.  
  1318.  
  1319. 10) Find Packets-: Browser Specific.
  1320. 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
  1321.  
  1322.  
  1323. 11)Inspect traffic between specific source and destination
  1324.  
  1325. Source 192.168.2.207 and destination 192.168.2.105
  1326.  
  1327.  
  1328. 12) Find out packet having good checksum value.
  1329.  
  1330.  
  1331.  
  1332.  
  1333. 13) To sniff communication between client and server
  1334. Java code for TcpClient.java
  1335. import java.net.*;
  1336. import java.io.*;
  1337.  
  1338. public class TcpClient
  1339. {
  1340. public staatic void main(Strin args[]) throws Exception
  1341.  
  1342. {
  1343. System.out.println("CLIENT");
  1344. byte b[]=new byte[1000];
  1345. Socket s1=new Siocket("IT_101",9000);
  1346. System.out.println("Server Found");
  1347.  
  1348. InputStream is=s1.getInputStream();
  1349.  
  1350. BufferedReader br=new BufferedReader(new InputStreamReader(is));
  1351. System.out.println(br.readLine());
  1352. OutputStream os=s1.getOutputStream();
  1353. System.in.read(b,0,1000);
  1354. os.write(b);
  1355. }
  1356. }
  1357. Java code for TcpServer.java
  1358. import java.io.*;
  1359. import java.net.*;
  1360.  
  1361. public class TcpServer
  1362. {
  1363. public static void main(String args[]) throws Exception
  1364.  
  1365. {
  1366. OutputStream os;
  1367. System.out.println("SERVER");
  1368. ServerSocket ss = new ServerSocket(9000);
  1369. Socket s1=ss.accept();
  1370.  
  1371. os=s1.getOutputStream();
  1372. byte b[]=new byte[1000];
  1373. System.out.println("Client Connected");
  1374. System.out.println("Enter your message");
  1375. System.in.read(b,0,b.length);
  1376. os.write(b);
  1377.  
  1378. InputStream is=s1.getInputStream();
  1379. BufferedReader br=new BufferedReader(new InputStreamReader(is));
  1380. System.out.println(br.readLine());
  1381. }
  1382. }
  1383. Compiling and running the java server code on server machine
  1384.  
  1385. Compiling and running the java server code on client machine
  1386.  
  1387. Open Wireshark
  1388. In Filter tcp.stream eq 1
  1389.  
  1390. Select ip address 192.168.2.201 and right click,select follow-Tcp Stream
  1391.  
  1392.  
  1393. Practical No.:9.c
  1394. Aim: Practical to perform mobile device forensic(Innovative Practical)
  1395. Software: Magnet Axiom
  1396. Code:
  1397. 1) Enter Case Details
  1398.  
  1399.  
  1400.  
  1401.  
  1402.  
  1403.  
  1404. 2) Acquire Evidence
  1405.  
  1406.  
  1407.  
  1408.  
  1409.  
  1410.  
  1411.  
  1412.  
  1413.  
  1414.  
  1415.  
  1416.  
  1417. 3) Load Evidence
  1418.  
  1419.  
  1420.  
  1421.  
  1422.  
  1423.  
  1424.  
  1425.  
  1426.  
  1427.  
  1428.  
  1429.  
  1430.  
  1431.  
  1432. 4) Analyze Evidence
  1433.  
  1434.  
  1435.  
  1436.  
  1437.  
  1438.  
  1439.  
  1440.  
  1441.  
  1442.  
  1443.  
  1444.  
  1445.  
  1446.  
  1447.  
  1448.  
  1449.  
  1450.  
  1451.  
  1452.  
  1453.  
  1454.  
  1455.  
  1456. 5)Examine Evidence
  1457.  
  1458.  
  1459.  
  1460.  
  1461.  
  1462.  
  1463.  
  1464.  
  1465.  
  1466.  
  1467.  
  1468.  
  1469.  
  1470.  
  1471.  
  1472.  
  1473.  
  1474.  
  1475. 6)Bookmark
  1476.  
  1477.  
  1478.  
  1479.  
  1480.  
  1481.  
  1482.  
  1483.  
  1484. 7)Report Creation
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement