#Alamgir Hossain, CSE, JUST#Leap year check in python programming----------- year = input("Enter the year : ") if year%400==0: print "The year is leap year."elif year%4==0: if year%100!=0: print "The year is Leap year." else: print "The year is Not Leap Year."else: print "The year is Not Leap Year!!!"
Wednesday, February 7, 2018
Leap Year check in python programming
Palindrome number check in python programming
#Alamgir Hossain, CSE, JUST #Palindrome number check in python---------- num = input("Enter the number : ") n = num sum = 0 #Declare sum = 0 while num>0: remainder = num%10 sum = remainder + (sum*10) num = num/10 #print sum #print n if sum == n: print "The entered number is palindrome."else: print "The number is not palindrome."
User input and if-else condition in python
##Alamgir, CSE, JUST #If-else-ifelse condition check in python----------- f = input("Enter the first value : ") s = input("Enter the second value : ") print "Press 1 for add, 2 for sub, 3 for mul, 4 for div 5 for remainder : "c = input() if c==1: print "Addition of the thw number is : ",(f+b) elif c==2: print "Subtraction of the two number is : ",(f-s) elif c==3: print "Multiplication of the two number is : ",(f*s) elif c==4: print "Division of the two number is : ",(f/s) elif c==5: print "Remainder of the two number is : ",f%s else: print "Please enter the valid input-----------" print "Thank you!!!!!!!!!!!!!!!!!!"
Monday, February 5, 2018
All instructions for connection & insert data in mysql from java JSP and Servlet using tomcat server
From this tutorial you can learn about...
All instructions for connection & insert data in mysql from java JSP and Servlet using tomcat server...
At first create a database "tutorialdb".
Now create a table student with 6 columns(Name,Uname,Password,Email,Subject,University);
Code :
CREATE TABLE `tutorialdb`.`student` (
`Name` varchar(100) NOT NULL,
`Uname` varchar(50) NOT NULL,
`Password` varchar(50) NOT NULL,
`Email` varchar(100) NOT NULL,
`Subject` varchar(50) NOT NULL,
`University` varchar(100) NOT NULL
)
Right click on your project and create a new jsp file. The jsp file name is : index.jsp
-------------------------------Code for index.jsp---------------------
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Mysql Database Connection using jsp, servlet and tomcat</title>
</head>
<body>
<h1>Md. Alamgir Hossain</h1>
<h1>Dept. of Computer Science & Engineering</h1>
<h1>Jessore University of Science & Technology</h1>
<form action="firstdbserv" method="Post">
Name : <input type="text" name="name"><br><br>
User Name : <input type="text" name="uname"><br><br>
Password : <input type="password" name="pass"><br><br>
Email : <input type="text" name="email"><br><br>
Subject : <input type="text" name="subject"><br><br>
University :<input type="text" name="university"><br><br>
<input type="submit" value="Submit"><br>
</form>
</body>
</html>
Now right click on src folder and take a new servlet and our servlet name is firstdbserv.java
-------------------------------- Code for firstdbserv.java-----------------------------
package eduhelp.serv;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* Servlet implementation class firstdbserv
*/
@WebServlet("/firstdbserv")
public class firstdbserv extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public firstdbserv() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
response.getWriter().append("Served at: ").append(request.getContextPath());
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
doGet(request, response);
PrintWriter out = response.getWriter();
String name = request.getParameter("name");
String uname = request.getParameter("uname");
String password = request.getParameter("pass");
String email = request.getParameter("email");
String subject = request.getParameter("subject");
String university = request.getParameter("university");
try {
Class.forName("com.mysql.jdbc.Driver");
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/tutorialDb","root","");
Statement st = conn.createStatement();
String sql = "insert into student (Name,Uname,Password,Email,Subject,University) values('"+name+"','"+uname+"','"+password+"','"+email+"','"+subject+"','"+university+"')";
st.executeUpdate(sql);
out.println("Data is Successfully Inserted into Student Table");
}catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
Save all files and run the index.jsp file.
Now check your database.....................
See all instructions in this video
All instructions for connection & insert data in mysql from java JSP and Servlet using tomcat server...
At first create a database "tutorialdb".
Now create a table student with 6 columns(Name,Uname,Password,Email,Subject,University);
Code :
CREATE TABLE `tutorialdb`.`student` (
`Name` varchar(100) NOT NULL,
`Uname` varchar(50) NOT NULL,
`Password` varchar(50) NOT NULL,
`Email` varchar(100) NOT NULL,
`Subject` varchar(50) NOT NULL,
`University` varchar(100) NOT NULL
)
Right click on your project and create a new jsp file. The jsp file name is : index.jsp
-------------------------------Code for index.jsp---------------------
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Mysql Database Connection using jsp, servlet and tomcat</title>
</head>
<body>
<h1>Md. Alamgir Hossain</h1>
<h1>Dept. of Computer Science & Engineering</h1>
<h1>Jessore University of Science & Technology</h1>
<form action="firstdbserv" method="Post">
Name : <input type="text" name="name"><br><br>
User Name : <input type="text" name="uname"><br><br>
Password : <input type="password" name="pass"><br><br>
Email : <input type="text" name="email"><br><br>
Subject : <input type="text" name="subject"><br><br>
University :<input type="text" name="university"><br><br>
<input type="submit" value="Submit"><br>
</form>
</body>
</html>
Now right click on src folder and take a new servlet and our servlet name is firstdbserv.java
-------------------------------- Code for firstdbserv.java-----------------------------
package eduhelp.serv;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* Servlet implementation class firstdbserv
*/
@WebServlet("/firstdbserv")
public class firstdbserv extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public firstdbserv() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
response.getWriter().append("Served at: ").append(request.getContextPath());
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
doGet(request, response);
PrintWriter out = response.getWriter();
String name = request.getParameter("name");
String uname = request.getParameter("uname");
String password = request.getParameter("pass");
String email = request.getParameter("email");
String subject = request.getParameter("subject");
String university = request.getParameter("university");
try {
Class.forName("com.mysql.jdbc.Driver");
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/tutorialDb","root","");
Statement st = conn.createStatement();
String sql = "insert into student (Name,Uname,Password,Email,Subject,University) values('"+name+"','"+uname+"','"+password+"','"+email+"','"+subject+"','"+university+"')";
st.executeUpdate(sql);
out.println("Data is Successfully Inserted into Student Table");
}catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
Save all files and run the index.jsp file.
Now check your database.....................
See all instructions in this video
Python code for Implement the Domain name system( DNS) using wireshark.
- from mininet.cli import CLI
- from mininet.log import setLogLevel
- from mininet.net import Mininet
- from mininet.topo import Topo
- def runMultiLink():
- "Create and run multiple link network"
- topo = simpleMultiLinkTopo( n=1 )
- net = Mininet( topo=topo )
- net.start()
- CLI( net )
- net.stop()
- class simpleMultiLinkTopo( Topo ):
- "Simple topology with multiple links"
- def __init__( self, n, **kwargs ):
- Topo.__init__( self, **kwargs )
- h1, h2, h3 = self.addHost( 'h1' ), self.addHost( 'h2' ), self.addHost( 'h3' )
- s1 = self.addSwitch( 's1' )
- s2 = self.addSwitch( 's2' )
- for _ in range( 1 ):
- self.addLink( s1, h1 )
- self.addLink( s1, h2 )
- self.addLink( s1, h3 )
- self.addLink( s2, h1 )
- self.addLink( s2, h2 )
- self.addLink( s2, h3 )
- if __name__ == '__main__':
- setLogLevel( 'info' )
- runMultiLink()
Implement the Domain name system or DNS system using wireshark.
Name of the
Experiment: Implement the Domain name system( DNS) using wireshark.
Introduction:
The Domain Name System
(DNS ) is a hierarchical decentralized naming system for computers, services,
or other resources connected to the
Internet or a private network.
It associates various information with domain names assigned to each of the
participating entities. Most prominently, it translates more readily memorized
domain names to the numerical IP addresses needed for locating and identifying
computer services and devices with the underlying network protocols. By
providing a worldwide, distributed directory service, the Domain Name System is
an essential component of the functionality on the Internet, that has been in
use since 1985.
Objectives:
Our
primary goal is to deeply understand the IP Addressing & Sub-netting
concepts and prepare ourselves to create an IP addressing plan for our
network. The main objectives of this project can be summarized as:
· 1.
A general understanding of IP addressing and
sub-netting.
· 2.
General IP addressing guidance while redesigning
an existing network.
· 3.
An understanding of DNS (Domain Name System).
· 4.
Guidance on how to add new services to an
existing network.
· 5.
To create a virtual network architecture of IP
addressing and sub-netting using cisco simulator.
· 6.
To provide a DNS server for IP addressing and
sub-netting.
· 7.
To show the connection between every node using
mininet on Linux.
· 8.The Domain Name
System delegates the responsibility of assigning domain names and mapping those
names to Internet resources by designating authoritative name servers for each
domain. Network administrators may delegate authority over sub-domains of their
allocated name space to other name servers. This mechanism provides distributed
and fault tolerant service and was designed to avoid a single large central
database.
· 9.The Domain Name
System also specifies the technical functionality of the database service that
is at its core. It defines the DNS protocol, a detailed specification of the
data structures and data communication exchanges used in the DNS, as part of
the Internet Protocol Suite . Historically, other directory services preceding
DNS were not scalable to large or global directories as they were originally
based on text files, prominently the hosts file.
· 10.The Internet
maintains two principal namespaces,
the
domain name hierarchy [1] and the Internet Protocol (IP) address spaces . [2]
The Domain Name System System maintains
the domain name hierarchy and provides translation services between it and the
address spaces.
Methodology:
As for our
resource limitations we have confined our project to simulation rather than
implementing the real network. The real implementation may worth it. As the
real server & client PC, router is very costly & can’t be resolved for
testing we used Cisco simulator which is all free & easy to understand as
well as to use.
In cisco we have
constructed a virtual network architecture of IP addressing and subnet
concepts. A DNS (Domain number Server) is used to provide the functionality of
Domain Name to IP addressing mapping sub-netting. Another web server is used
for sub-netting concepts. We have used a switch to provide the connectivity
between all nodes. A router is used for routing between client to server or
vice versa. The two servers (one DNS other Web) , client PC,router are
connected together using some kind of copper cabling. The DNS server, web
server , client PC and router has given IP addresses as 192.168.10.254 ,
192.168.10.5 , 192.168.10.2 , 192.168.10.0. The subnet mask is 255.255.255.0.
The default gateway is 192.168.1.1. The DNS server is given a Domain Name named
www.dns.com & the web
server named www.web.com. The DNS server
maps Domain Name to IP address to route to the correct destination. The page
can be visited from client Pc by using both IP address and corresponding Domain
Name.
Now when the
virtual network creation is done it’s time for moving to next stage. The
virtual network now is created using virtual network creator mininet in Linux.
The network is now created using terminal of Linux & commands. The commands
are as follows:
Mininet
Installation:
·
Process
Step 1: $ sudo apt-get install git
·
Step
2: $ git clone git://github.com/mininet/mininet
·
Step
3: $ cd mininet
·
Step
4: $ git tag
·
Step
5: $ git checkout -b 2.2.0b3
·
Step
6: $ ~/mininet/util/install.sh -a
·
Step
7: $ sudo mn --test pingall
Wireshark
Installation
·
Process
Step 1: $ sudo apt-add-repository universe
·
Step
2: $ sudo apt-get update
·
Step
3: $ sudo apt-get install wireshark
Virtual network
creation
·
sudo
mn –c
·
sudo
mn
·
xterm
h1 h2
·
h2
: iperf -s -p 5566 -i 1
·
h1:
iperf -c 10.0.0.2 -p 5566 -t 15
Now once the
virtual network is created we need see whether the packet is passing or not.
For this purpose we used wireshark as mentioned earlier is a packet analyzer
software which is very efficient and magnificent piece of software. Mininet is
connected with wireshark then the status is observed. It has showed that many
packet is passing through several protocol including source , destination
addresses.
·
·
Input:
We are capturing traffic
by wiershark from the Ethernet port.
Figure:Wireshark input
Output:
We filtered the output by
DNS.The following figure is showing the expected output.
1
Figure:Wireshark output
Figure: Wireshark IO graph
Result
& Discussion:
From the output we
can see the result of filtered DNS. From the wiewshark IO graph we can observe
the packet passing filtered by DNS. The source and destination address is also
documented as we have seen in the output. In cisco simulator we successfully
browsed web server using both IP address and their corresponding Domain Name.
We have tested several live websites well as our own virtual network topology
using the command lookup. We observed
that it returns the web servers corresponding IP address by requesting several
DNS server.
Figure: Web browsing using Domain
Name
Conclusion:
All the nodes were
connected successfully and launched in simulator successfully. The DNS server
has successfully mapped Domain Name to IP addressing and the virtual
sub-netting was constructed .The network topology is created in mininet using
terminal of Linux and some sort of commands as we have seen in methodology. The
packet passing is observed using wireshark and graph as well created. Finally
we can say that the project is successfully launched and all the module is
tested properly.
--------------------------------------------*******************-----------------------------------------------------
Python Code for Domain Name System----
from mininet.cli import CLI
from mininet.log import setLogLevel
from mininet.net import Mininet
from mininet.topo import Topo
def runMultiLink():
"Create and run multiple link network"
topo = simpleMultiLinkTopo( n=1 )
net = Mininet( topo=topo )
net.start()
CLI( net )
net.stop()
class simpleMultiLinkTopo( Topo ):
"Simple topology with multiple links"
def __init__( self, n, **kwargs ):
Topo.__init__( self, **kwargs )
h1, h2, h3 = self.addHost( 'h1' ), self.addHost( 'h2' ), self.addHost( 'h3' )
s1 = self.addSwitch( 's1' )
s2 = self.addSwitch( 's2' )
for _ in range( 1 ):
self.addLink( s1, h1 )
self.addLink( s1, h2 )
self.addLink( s1, h3 )
self.addLink( s2, h1 )
self.addLink( s2, h2 )
self.addLink( s2, h3 )
if __name__ == '__main__':
setLogLevel( 'info' )
runMultiLink()