· 8 years ago · Jun 11, 2018, 04:56 PM
1
205/06/2018
3
4#Coding first.php (need to be updated)(st,et,ip,loc,date,submit)
5
6<html>
7<body>
8 <title> Pcap Pulling Automation </title>
9 <h1> Pcap Request <h1>
10
11<form method="post" action="">
12 Start time: <input type="text" name="st"><br>
13 End time: <input type="text" name="et"><br>
14 IP Address: <input type="text" name="ip" value = "Eg:10.0.0.125"><br>
15 Location: <select name="loc">
16 <option>9a</option>
17 <option>9b</option>
18 <option>9c</option>
19 <option>9d</option>
20 <option>9e</option>
21 </select><br>
22 date:<input type="date" id="datepicker" name='from' size='9' value="" /><br>
23 <input type="submit" name="sub" value="Submit">
24</form>
25<?php
26
27?>
28</html>
29</body>
30
31#Creating and Manage Databases in MySQL and MariaDB
32CREATE DATABASE pcapinfo;
33
34Query OK, 1 row affected (0.00 sec)
35
36#Viewing Databases
37SHOW DATABASES;
38
39+--------------------+
40| Database |
41+--------------------+
42| information_schema |
43| mysql |
44| new |
45| newdb |
46| pcapinfo |
47| performance_schema |
48| phpmyadmin |
49| testing1 |
50+--------------------+
518 rows in set (0.00 sec)
52
53#Find out which database is currently selected
54SELECT database();
55
56+------------+
57| database() |
58+------------+
59| NULL |
60+------------+
611 row in set (0.01 sec)
62
63#Changing Databases
64USE new_database;
65
66Database changed
67
68#We can see that the database has been selected by re-issuing the command we ran previously:
69
70SELECT database();
71
72+--------------+
73| database() |
74+--------------+
75| new_database |
76+--------------+
771 row in set (0.00 sec)
78
79#Delete a Database
80
81DROP DATABASE new_database;
82
83Query OK, 0 rows affected (0.00 sec)
84
85#Creating a table
86
87CREATE TABLE IF NOT EXISTS info (
88 st int(5) NOT NULL,
89 et int(5) NOT NULL,
90 ip int(5) NOT NULL,
91 loc varchar(20) DEFAULT NULL
92 );
93
94Query OK, 0 rows affected (0.03 sec)
95
96#Defining Columns
97show columns in info;
98
99+-------+-------------+------+-----+---------+-------+
100| Field | Type | Null | Key | Default | Extra |
101+-------+-------------+------+-----+---------+-------+
102| st | int(5) | NO | | NULL | |
103| et | int(5) | NO | | NULL | |
104| ip | int(5) | NO | | NULL | |
105| loc | varchar(20) | NO | | NULL | |
106+-------+-------------+------+-----+---------+-------+
1074 rows in set (0.00 sec)
108
109
110#Inserting Data
111syntax:
112
113INSERT INTO table_name (field1, field2, ...) VALUES (value1, value2, ...);
114
115INSERT INTO info (st, et, ip, loc)
116VALUES
117(11, 12, 15, "del");
118
119
120#To see the information, query the table. The asterisk (*) is a special wildcard character that matches everything.
121 SELECT * FROM info;
122
123+----+----+----+---------+
124| st | et | ip | loc |
125+----+----+----+---------+
126| 11 | 12 | 10 | chennai |
127| 11 | 12 | 15 | del |
128+----+----+----+---------+
1292 rows in set (0.00 sec)
130
131#Deleting a table
132
133DROP TABLE table_name;
134
135
13607/06/2018
137
138#Creating second.php to display the data which is been inputed
139
140<html>
141<body>
142
143The date you have entered is: <?php echo $_POST["datevar"]; ?><br>
144The Start Time is: <?php echo $_POST["st"]; ?><br>
145The End Time is: <?php echo $_POST["et"]; ?><br>
146The IP is: <?php echo $_POST["ip"]; ?><br>
147The Location is: <?php echo $_POST["loc"]; ?>
148
149</body>
150</html>
151
152#Creating test.php to testing connect to db
153
154 <?php
155$servername = "localhost";
156$username = "username";
157$password = "userpassword";
158$DBname = "pcapinfo";
159
160// Create connection
161$conn = mysqli_connect($servername, $username, $password, $DBname);
162
163// Check connection
164if (!$conn) {
165 die("Connection failed: " . mysqli_connect_error());
166}
167else{
168 echo "Connected successfully <br>";
169}
170$sql = "INSERT INTO info (st,et,ip,loc) VALUES ('6:30', '7:30', '10.22.22.22', 'FROMWebPAGE');";
171
172//$sql = "SHOW DATABASES;";
173
174/*if ($conn->mysqli_query($sql) === TRUE) {
175 echo "New record created successfully";
176}
177else {
178 echo "Error: " . $sql . "<br>" . $conn->error;
179}*/
180
181
182if ($result = $mysqli->query($sql)) {
183 printf("Select returned %d rows.\n", $result->num_rows);
184 $result->close();
185}
186
187$conn->close();
188
189?>
190
191#Creating /var/www/html/new/1a.php/ improved connection file
192
193<?php
194$link = mysqli_connect("localhost", "newusername", "userpassword", "database1");
195
196if (!$link) {
197 echo "Error: Unable to connect to MySQL." . PHP_EOL;
198 echo "Debugging errno: " . mysqli_connect_errno() . PHP_EOL;
199 echo "Debugging error: " . mysqli_connect_error() . PHP_EOL;
200 exit;
201}
202
203echo "Success: A proper connection to MySQL was made! The database1 database is great." . PHP_EOL;
204echo "Host information: " . mysqli_get_host_info($link) . "<br>" . PHP_EOL;
205
206echo "NIB 1 <br>";
207
208
209/* return name of current default database */
210if ($result = $link->query("SELECT DATABASE()")) {
211 $row = $result->fetch_row();
212 printf("Default database is %s.\n", $row[0]);
213 $result->close();
214}
215
216echo "<br> NIB 2 <br>";
217
218/* change db to world db */
219$link->select_db("pcapinfo");
220
221/* return name of current default database */
222if ($result = $link->query("SELECT DATABASE()")) {
223 $row = $result->fetch_row();
224 printf("The Changed database is %s.\n", $row[0]);
225 $result->close();
226}
227
228echo "<br> NIB 3 <br>";
229
230/* Select queries return a resultset */
231if ($result = $link->query("SELECT * FROM info")) {
232 printf("Select returned %d rows.\n", $result->num_rows);
233 /* free result set */
234 $result->close();
235}
236
237/* Select queries return a resultset */
238if ($result = $link->query("INSERT INTO info (st,et,ip,loc) VALUES ('6:30', '7:30', '10.22.22.22', 'NIB');")) {
239 /*printf("Select returned %d rows.\n", $result->num_rows);
240 free result set */
241 $result->close();
242}
243mysqli_close($link);
244?>
245
246
247
24811/06/2018
249
250# To Modify table
251MariaDB [pcapinfo]> ALTER TABLE info MODIFY et VARCHAR(30);
252Query OK, 9 rows affected (0.35 sec)
253Records: 9 Duplicates: 0 Warnings: 0
254
255MariaDB [pcapinfo]> SHOW FIELDS FROM info;
256+-------+-------------+------+-----+---------+-------+
257| Field | Type | Null | Key | Default | Extra |
258+-------+-------------+------+-----+---------+-------+
259| st | int(5) | NO | | NULL | |
260| et | varchar(30) | YES | | NULL | |
261| ip | int(5) | NO | | NULL | |
262| loc | varchar(20) | NO | | NULL | |
263+-------+-------------+------+-----+---------+-------+
2644 rows in set (0.00 sec)
265
266MariaDB [pcapinfo]> ALTER TABLE info MODIFY st VARCHAR(30);
267Query OK, 9 rows affected (0.40 sec)
268Records: 9 Duplicates: 0 Warnings: 0
269
270MariaDB [pcapinfo]> ALTER TABLE info MODIFY ip VARCHAR(30);
271Query OK, 9 rows affected (0.25 sec)
272Records: 9 Duplicates: 0 Warnings: 0
273
274MariaDB [pcapinfo]> SHOW FIELDS FROM info;
275+-------+-------------+------+-----+---------+-------+
276| Field | Type | Null | Key | Default | Extra |
277+-------+-------------+------+-----+---------+-------+
278| st | varchar(30) | YES | | NULL | |
279| et | varchar(30) | YES | | NULL | |
280| ip | varchar(30) | YES | | NULL | |
281| loc | varchar(20) | NO | | NULL | |
282+-------+-------------+------+-----+---------+-------+
2834 rows in set (0.00 sec)
284
285ALTER TABLE info ADD COLUMN pcaphash VARCHAR(100) AFTER loc;
286
287
288
289#Second.php (display info, calculate the hash with date-st,et,ip,loc, Establishing a connection, inserting values in the DB)
290<html>
291<body>
292
293<?php
294$datevari=$_POST["datevar"];
295$stime=$_POST["st"];
296//Here I am trying to concate Date and time
297$stime="$datevari" . " $stime";
298$etime=$_POST["et"];
299$etime="$datevari" . " $etime";
300$ipaddr=$_POST["ip"];
301$location=$_POST["loc"];
302
303$pcaphash="$stime" . "$etime" . "$ipaddr" . "$location";
304
305
306echo "The date you have entered is " . $datevari . "<br>";
307echo "The start time is" . $stime . "<br>";
308echo "The end time is" . $etime . "<br>";
309echo "The IP address is" . $ipaddr . "<br>";
310echo "The location is" . $location . "<br>";
311echo "The pcaphash string value is <b>" . $pcaphash . "</b> <br>";
312
313//echo hash('md5', $pcaphash) . "<br>";
314$pcaphash=hash('md5', $pcaphash);
315echo "The pcaphash value is <b>" . $pcaphash . "</b> <br>";
316
317
318echo "<br><br><br>";
319
320
321$link = mysqli_connect("localhost", "newusername", "userpassword", "database1");
322
323if (!$link) {
324 echo "Error: Unable to connect to MySQL." . PHP_EOL;
325 echo "Debugging errno: " . mysqli_connect_errno() . PHP_EOL;
326 echo "Debugging error: " . mysqli_connect_error() . PHP_EOL;
327 exit;
328}
329
330echo "Success: A proper connection to MySQL was made! The database1 database is great." . PHP_EOL;
331
332echo "Host information: " . mysqli_get_host_info($link) . "<br>" . PHP_EOL;
333
334
335/* return name of current default database */
336if ($result = $link->query("SELECT DATABASE()")) {
337 $row = $result->fetch_row();
338 printf("Default database is %s.\n", $row[0]);
339 $result->close();
340}
341
342/* change db to world db */
343$link->select_db("pcapinfo");
344
345/* return name of current default database */
346if ($result = $link->query("SELECT DATABASE()")) {
347 $row = $result->fetch_row();
348 printf("The Changed database is %s.\n", $row[0]);
349 $result->close();
350}
351
352/* Select queries return a resultset */
353if ($result = $link->query("SELECT * FROM info")) {
354 printf("Select returned %d rows.\n", $result->num_rows);
355 /* free result set */
356 $result->close();
357}
358
359//echo "INSERT INTO info VALUES ( \"$stime\", \"$etime\" , \"$ipaddr\", \"$location\");";
360
361$link->query("INSERT INTO info VALUES ( \"$stime\", \"$etime\" , \"$ipaddr\", \"$location\", \"$pcaphash\");");
362
363
364
365/*This will retrieve values from the DB
366
367
368 //$query = "SELECT * from info;";
369
370 echo "======================<br>";
371 //echo "My query is " . $query . "<br>";
372
373 if ($result = $link->query("SELECT * from info")) {
374
375 /* Get field information for all columns */
376 $finfo = $result->fetch_fields()
377
378 echo "My finfo variable is " . $finfo . "<br>";
379 echo "My first index is " . finfo[0] . "<br>"; */
380
381/*
382 //Creates a loop to loop through results
383 while(){
384 //$row['index'] the index here is a field name
385 //echo "<tr><td>" . $row['st'] . "</td><td>" . $row['et'] . "</td><td>" . $row['ip'] . "</td><td>" . $row['loc'] . "</td><td>" . $row['pcaphash'] . "</td></tr>";
386 echo $row["st"];
387 echo $finfo->st;
388 }
389*/
390
391/*
392 foreach ($finfo as $val) {
393 //echo "My val variable is " . $val . "<br>";
394 printf("st: %s", $val->st);
395 printf("et: %s", $val->et);
396 printf("ip: %s", $val->ip);
397 printf("loc: %s", $val->loc);
398 printf("pcaphash: %s", $val->pcaphash);
399 echo "<br>";
400 }
401
402*/
403 $result->free();
404 }
405
406$link->close();
407?>
408</body>
409</html>
410
411
412
413#Tableview.php
414
415<?php
416// Establishing a connection to DB
417$link = mysqli_connect("localhost", "newusername", "userpassword", "pcapinfo");
418
419if (!$link) {
420 echo "Error: Unable to connect to MySQL." . PHP_EOL;
421 echo "Debugging errno: " . mysqli_connect_errno() . PHP_EOL;
422 echo "Debugging error: " . mysqli_connect_error() . PHP_EOL;
423 exit;
424}
425echo "Success: A proper connection to MySQL was made! The database1 database is great." . PHP_EOL;
426echo "Host information: " . mysqli_get_host_info($link) . "<br>" . PHP_EOL;
427
428$sql = 'SELECT * FROM info';
429// mysqli_query(connection,query,resultmode); //performs a query against the database.
430$query = mysqli_query($link, $sql);
431// Creating a table
432echo "<table border=1>";
433echo"<tr>
434<td>Start Time</td>
435<td>End Time</td>
436<td>IP Address</td>
437<td>Location</td>
438<td>Hash Value</td>
439</tr>";
440// mysqli_fetch_array(result,resulttype); //fetches a result row as an associative array, a numeric array, or both.
441while ($row = mysqli_fetch_array($query))
442{
443echo '<tr>
444<td>'.$row['st'].'</td>
445<td>'.$row['et'].'</td>
446<td>'.$row['ip'].'</td>
447<td>'.$row['loc'].'</td>
448<td>'.$row['pcaphash'].'</td>
449</tr>';
450}
451echo "</table>";
452?>