Thursday, October 30, 2014
Write a program to Implement a fingerprint recognition using Java Programming
Problem Statement:
Write a program to Implement a fingerprint recognition using Java Programming
OUTPUT:
Write a program to Implement a fingerprint recognition using Java Programming
PROGRAM
import java.awt.Image;
import java.awt.Toolkit;
import java.awt.image.PixelGrabber;
import java.io.File;
class fingerprint{
public static void main(String args[]){
try {
String file1 = "sq.png";
String file2 = "sq.png";
Image pic1=
Toolkit.getDefaultToolkit().getImage(file1);
Image pic2=
Toolkit.getDefaultToolkit().getImage(file2);
try {
PixelGrabber grab11 = new
PixelGrabber(pic1, 0, 0, -1, -1,
false);
PixelGrabber grab21 = new
PixelGrabber(pic2, 0, 0, -1, -1,
false);
int array1[]= null;
if (grab11.grabPixels()) {
int width = grab11.getWidth();
int height = grab11.getHeight();
array1= new int[width * height];
array1= (int[]) grab11.getPixels();
}
int[] array2 = null;
if (grab21.grabPixels()) {
int width = grab21.getWidth();
int height = grab21.getHeight();
array2 = new int[width * height];
array2 = (int[]) grab21.getPixels();
}
System.out.println("Pixels
equal: "
+ java.util.Arrays.equals(array1, array2
));
} catch (InterruptedException e1) {
e1.printStackTrace();
}
} catch (Throwable t) {
// report error
System.out.println("Fail - " +
t.getMessage());
}
}
}
pict@locathost-Inspiron-5537:~$ javac
fingerprint.java
pict@locathost-Inspiron-5537:~$ java
fingerprint
Pixels equal:
false
pict@locathost-Inspiron-5537:~$ javac
fingerprint.java
pict@locathost-Inspiron-5537:~$ java
fingerprint
Pixels equal: true
Design and implementation of Honeypot
Problem Statement:
Design and implementation of Honeypot
Design and implementation of Honeypot
PROGRAM
#!/usr/bin/env python
#Name: pyp0t.py
#Version: 0.2
#Author: s3my0n
import time
import socket
def getstuff():
banner = raw_input('\nEnter banner information: ')
host = raw_input('Enter IP Address: ')
while True:
try:
port = int(raw_input('Enter Port Number: '))
except TypeError:
print '\n[-] Error: invalid port number\n'
continue
else:
if (port < 1) or (port > 65535):
print '\n[-] Error: invalid port number\n'
continue
else:
return (banner, host, port)
def writelog(client, data=''):
separator = '='*40
fopen = open('\\home\\potlog.txt', 'a')
fopen.write('Time: %s\nIP Address: %s\nPort: %d\n\n%s%s\n\n'%(time.ctime(), client[0], fopen.close()
def main(host, port, banner):
print '\n[*] Listening ...\n'
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((host, port))
s.listen(100)
while True:
(insock, address) = s.accept()
print '[*] Connection from: %s:%d' % (address[0], address[1])
try:
insock.send('%s\n'%(banner))
data = insock.recv(1024)
insock.close()
except socket.error, e:
writelog(address)
else:
writelog(address, data)
if __name__=='__main__':
try:
stuff = getstuff()
main(stuff[1], stuff[2], stuff[0])
except KeyboardInterrupt:
print '\n\n[+] Exiting...'
exit(0)
except BaseException, e:
print '\n[-] Error: %s' % (e)
exit(1)
OUTPUT
Log capturing and event correlation
Problem Statement:
Write a C++/Java program for Log Capturing and Event Correlation.
mainWindow.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
private slots:
void on_pushButton_3_clicked();
void on_pushButton_clicked();
void on_pushButton_2_clicked();
private:
Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H
******************************************************************
mainWindow.cpp
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "QFile"
#include "QTextStream"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_pushButton_3_clicked()
{
QFile file("/var/log/yum.log");
if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
return;
QString line1=" ";
QTextStream in(&file);
while (!in.atEnd()) {
QString line = in.readLine();
line1.append(line+ "\n");
}
ui->textEdit->setText(line1);
}
void MainWindow::on_pushButton_clicked()
{
ui->textEdit->clear();
QFile file("/var/log/yum.log");
if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
return;
QString line1=" ";
QTextStream in(&file);
while (!in.atEnd()) {
QString line = in.readLine();
if(line.count("Updated")!=0)
{
line1.append(line+"\n");
}
}
ui->textEdit->setText(line1);
}
void MainWindow::on_pushButton_2_clicked()
{
ui->textEdit->clear();
QFile file("/var/log/yum.log");
if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
return;
QString line1=" ";
QTextStream in(&file);
while (!in.atEnd()) {
QString line = in.readLine();
if(line.count("Installed")!=0)
{
line1.append(line+"\n");
}
}
ui->textEdit->setText(line1);
}
OUTPUT
Write a C++/Java program for Log Capturing and Event Correlation.
PROGRAM
mainWindow.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
private slots:
void on_pushButton_3_clicked();
void on_pushButton_clicked();
void on_pushButton_2_clicked();
private:
Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H
******************************************************************
mainWindow.cpp
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "QFile"
#include "QTextStream"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_pushButton_3_clicked()
{
QFile file("/var/log/yum.log");
if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
return;
QString line1=" ";
QTextStream in(&file);
while (!in.atEnd()) {
QString line = in.readLine();
line1.append(line+ "\n");
}
ui->textEdit->setText(line1);
}
void MainWindow::on_pushButton_clicked()
{
ui->textEdit->clear();
QFile file("/var/log/yum.log");
if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
return;
QString line1=" ";
QTextStream in(&file);
while (!in.atEnd()) {
QString line = in.readLine();
if(line.count("Updated")!=0)
{
line1.append(line+"\n");
}
}
ui->textEdit->setText(line1);
}
void MainWindow::on_pushButton_2_clicked()
{
ui->textEdit->clear();
QFile file("/var/log/yum.log");
if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
return;
QString line1=" ";
QTextStream in(&file);
while (!in.atEnd()) {
QString line = in.readLine();
if(line.count("Installed")!=0)
{
line1.append(line+"\n");
}
}
ui->textEdit->setText(line1);
}
OUTPUT
Write a program to Implement a packet sniffing tool in C++/Java/Python.
Problem Statement:
Write a program to Implement a packet sniffing tool in C++/Java/Python.
Write a program to Implement a packet sniffing tool in C++/Java/Python.
PROGRAM
#Packet sniffer in python for
Linux
#Sniffs only incoming TCP
packet
import socket, sys
from struct import *
#create an INET, STREAMing
socket
try:
s = socket.socket(socket.AF_INET,
socket.SOCK_RAW, socket.IPPROTO_TCP)
except socket.error , msg:
print 'Socket could not be created. Error
Code : ' + str(msg[0]) + ' Message ' + msg[1]
sys.exit()
# receive a packet
while True:
packet = s.recvfrom(65565)
#packet string from tuple
packet = packet[0]
#take first 20 characters for the ip header
ip_header = packet[0:20]
#now unpack them :)
iph = unpack('!BBHHHBBH4s4s' , ip_header)
version_ihl = iph[0]
version = version_ihl >> 4
ihl = version_ihl & 0xF
iph_length = ihl * 4
ttl = iph[5]
protocol = iph[6]
s_addr = socket.inet_ntoa(iph[8]);
d_addr = socket.inet_ntoa(iph[9]);
print 'Version : ' + str(version) + ' IP
Header Length : ' + str(ihl) + ' TTL : ' + str(ttl) + ' Protocol : ' +
str(protocol) + ' Source Address : ' + str(s_addr) + ' Destination Address : '
+ str(d_addr)
tcp_header =
packet[iph_length:iph_length+20]
#now unpack them :)
tcph = unpack('!HHLLBBHHH' , tcp_header)
source_port = tcph[0]
dest_port = tcph[1]
sequence = tcph[2]
acknowledgement = tcph[3]
doff_reserved = tcph[4]
tcph_length = doff_reserved >> 4
print 'Source Port : ' + str(source_port) +
' Dest Port : ' + str(dest_port) + ' Sequence Number : ' + str(sequence) + '
Acknowledgement : ' + str(acknowledgement) + ' TCP header length : ' +
str(tcph_length)
h_size = iph_length + tcph_length * 4
data_size = len(packet) - h_size
#get data from the packet
data = packet[h_size:]
print 'Data : ' + data
A fire is to be detected using relevant wireless sensor network installed in a remote location to communicate the data to the central server for the monitoring purpose and detection of the fire. Write a program to implement the system using WSN and Different data communication strategies/ algorithms (at least two) to compare the reliability of the data received and efficient timing. Use of Fort Forwarding/Tunneling Protocol is expected.
Problem Statement:
A fire is to be detected using relevant wireless sensor network installed in a remote location to communicate the data to the central server for the monitoring purpose and detection of the fire. Write a program to implement the system using WSN and Different data communication strategies/ algorithms (at least two) to compare the reliability of the data received and efficient timing. Use of Fort Forwarding/Tunneling Protocol is expected.
A fire is to be detected using relevant wireless sensor network installed in a remote location to communicate the data to the central server for the monitoring purpose and detection of the fire. Write a program to implement the system using WSN and Different data communication strategies/ algorithms (at least two) to compare the reliability of the data received and efficient timing. Use of Fort Forwarding/Tunneling Protocol is expected.
PROGRAM
Psqldatabase.cpp
#include "stdafx.h"
#include <string>
#include "libpq-fe.h"
/* Close connection to database */
void CloseConn(PGconn
*conn)
{
PQfinish(conn);
getchar();
exit(1);
}
/* Establish connection to database */
PGconn
*ConnectDB()
{
PGconn *conn = NULL;
conn = PQconnectdb("user=postgres password=server123 dbname=testdb hostaddr=127.0.0.1 port=5432");
if (PQstatus(conn) != CONNECTION_OK)
{
printf("Connection to database failed");
CloseConn(conn);
}
printf("Connection to database - OK\n");
return conn;
}
// Creating Sensor table
void CreateEmployeeTable(PGconn *conn)
{
// Execute with sql statement
PGresult *res = PQexec(conn, "CREATE TABLE sensor (Node char(30), Temperature char(30))");
if (PQresultStatus(res) != PGRES_COMMAND_OK)
{
printf("Create sensor table failed");
PQclear(res);
CloseConn(conn);
}
printf("Create sensor table - OK\n");
PQclear(res);
}
/* Append SQL statement and insert record into employee table */
void InsertEmployeeRec(PGconn *conn, char * Node, char * Temperature)
{
// Append the SQL statment
std::string sSQL;
sSQL.append("INSERT INTO sensor VALUES ('");
sSQL.append(Node);
sSQL.append("', '");
sSQL.append(Temperature);
sSQL.append("')");
// Execute with sql statement
PGresult *res = PQexec(conn, sSQL.c_str());
if (PQresultStatus(res) != PGRES_COMMAND_OK)
{
printf("Insert sensor record failed");
PQclear(res);
CloseConn(conn);
}
printf("Insert sensor record - OK\n");
PQclear(res);
}
void Alarm(char * temp)
{
printf("Fire detected at : %-30s", temp );
}
// Check whether fire is detected
void CheckFire(PGconn *conn)
{
int nFields;
// Start a transaction block
PGresult *res = PQexec(conn, "BEGIN");
if (PQresultStatus(res) != PGRES_COMMAND_OK)
{
printf("BEGIN command failed");
PQclear(res);
CloseConn(conn);
}
PQclear(res);
// Fetch rows from sensor table
res = PQexec(conn, "DECLARE emprec CURSOR FOR select * from sensor");
if (PQresultStatus(res) != PGRES_COMMAND_OK)
{
printf("DECLARE CURSOR failed");
PQclear(res);
CloseConn(conn);
}
// Clear result
PQclear(res);
res = PQexec(conn, "FETCH ALL in emprec");
if (PQresultStatus(res) != PGRES_TUPLES_OK)
{
printf("FETCH ALL failed");
PQclear(res);
CloseConn(conn);
}
nFields = PQnfields(res);
char * temp;
for (int i = 0; i < PQntuples(res); i++)
{
for (int j = 0; j < nFields; j++)
{
if(j == 0 )
{ temp = PQgetvalue(res, i, j); }
if(j == 1 )
{
int a = atoi(PQgetvalue(res, i, j));
if( a >= 20) { Alarm(temp); }
// Set the threshold value
// printf("%d", a);
}
printf("\n");
}
}
PQclear(res);
res = PQexec(conn, "CLOSE emprec");
PQclear(res);
res = PQexec(conn, "END");
PQclear(res);
}
/* Fetch sensor record and display it on screen */
void FetchEmployeeRec(PGconn
*conn)
{
// Will hold the number of field in sensor table
int nFields;
// Start a transaction block
PGresult *res = PQexec(conn, "BEGIN");
if (PQresultStatus(res) != PGRES_COMMAND_OK)
{
printf("BEGIN command failed");
PQclear(res);
CloseConn(conn);
}
// Clear result
PQclear(res);
// Fetch rows from sensor table
res = PQexec(conn, "DECLARE emprec CURSOR FOR select * from sensor");
if (PQresultStatus(res) != PGRES_COMMAND_OK)
{
printf("DECLARE CURSOR failed");
PQclear(res);
CloseConn(conn);
}
// Clear result
PQclear(res);
res = PQexec(conn, "FETCH ALL in emprec");
if (PQresultStatus(res) != PGRES_TUPLES_OK)
{
printf("FETCH ALL failed");
PQclear(res);
CloseConn(conn);
}
// Get the field name
nFields = PQnfields(res);
// Prepare the header with sensor table field name
printf("\nFetch sensor record:");
printf("\n********************************************************************\n");
for (int i = 0; i < nFields; i++)
printf("%-30s", PQfname(res, i));
printf("\n********************************************************************\n");
// Next, print out the sensor record for each row
for (int i = 0; i < PQntuples(res); i++)
{
for (int j = 0; j < nFields; j++)
printf("%-30s", PQgetvalue(res, i, j));
printf("\n");
}
PQclear(res);
// Close the emprec
res = PQexec(conn, "CLOSE emprec");
PQclear(res);
// End the transaction
res = PQexec(conn, "END");
// Clear result
PQclear(res);
}
/* Erase all record in sensor table */
void RemoveAllEmployeeRec(PGconn
*conn)
{
// Execute with sql statement
PGresult *res = PQexec(conn, "DELETE FROM sensor");
if (PQresultStatus(res) != PGRES_COMMAND_OK)
{
printf("Delete sensor record failed.");
PQclear(res);
CloseConn(conn);
}
printf("\nDelete sensor record - OK\n");
// Clear result
PQclear(res);
}
/* Drop employee table from the database*/
void DropEmployeeTable(PGconn
*conn)
{
// Execute with sql statement
PGresult *res = PQexec(conn, "DROP TABLE sensor");
if (PQresultStatus(res) != PGRES_COMMAND_OK)
{
printf("Drop sensor table failed.");
PQclear(res);
CloseConn(conn);
}
printf("Drop sensor table - OK\n");
// Clear result
PQclear(res);
}
int _tmain(int argc, _TCHAR* argv[])
{
PGconn *conn = NULL;
conn = ConnectDB();
FetchEmployeeRec(conn);
CheckFire(conn);
printf("\nPress ENTER to remove all records & table.....\n");
getchar();
RemoveAllEmployeeRec(conn);
DropEmployeeTable(conn);
CloseConn(conn);
return 0;
}
OUTPUT
Subscribe to:
Posts (Atom)
Perform a suitable assignment using Xen Hypervisor or equivalent open source to configure it. Give necessary GUI.
To install kvm on Fedora: yum install kvm yum install virt-manager libvirt libvirt-python python-virtinst su -c "yum install @v...
-
Problem Statement: A person on a nearby road is trying to enter into a WiFi network by trying to crack the Password to use ...
-
Problem Statement: Write a C++/Java program for Log Capturing and Event Correlation. PROGRAM mainWindow.h #ifndef M...
-
Opencl Installation: Use superuser permission for given steps. 1. Download AMD-APP-SDK-linux-v2.9-1.599.381-GA-x64.tar.bz2 from intern...