So hello everyone in this video. We are
going to see how you can utilize nmamp libraries
to perform scans with the
help of python.
So the first and the foremost thing that you have to
do is you need to install the
Python and map Library so you need
to import the nmap module to your python script
and then you can start so for that you
just need to type this particular command, which is PIP install
python hyphen and map so I
will just open up my terminal and I will paste it over here.
As you can see the requirement already satisfied which
means I have already installed this particular Library,
so we are good to go. I will just clear
my screen.
and
Now, let's quickly start Python and import the
nmap library. So for that I just need to
type python.
And now I can import and map.
After I have imported nmap.
Then we can initialize the nmap port scanner
to scan our ports onto our local network.
Okay. So first about what we are going to do is we
are going to initialize.
Our variable so let's say NM scan.
And which will initialize the port scanner
of nmap.
Let's type it like this.
alright
I have written all the steps already.
So that there are no mistakes while we are
executing our programs and no stack Trace errors.
So now
let's quickly scan.
Our network from these particular ports.
So this will return addition of the scan and it will get executed
on the local network that we are going to scan for
the port numbers between 21 to 443.
So let's just quickly.
run this
and wait
for the output
As you can see it has successfully executed and we
have also got the output over here.
But then you can see.
This is the Local Host which is scan.
And it is identified that Port 80 it is
running on TCP is open and the product is simple HTTP
server because yes, we are running a HTTP server
using nmap as you can
see over here. Yep. So I have a
run HTTP server and it is able to identify that.
You can see over here. It is able to identify it is python simple
HTTP server.
All right.
Let's move ahead and now.
You can use this particular command, which
is NM scan dot command line, which actually this
particular method will read the
scan method.
Call and generate an equivalent command for
running on command line. So let us
see what this output gives us.
So when I will hit enter you can see it will give me output something
like this.
So this is the command that I'm going to run.
So as you can see nmap, hyphen o x Port from
21 to 443. I'm going
to run this ports hyphen SV to show the
output in verbose mode and this is the loopback IP address.
So this is the command which we can run onto the
command line.
alright
now
for the scan that we have run we can use this particular.
Method which is scan info. So let's see if you use this
then what output do we get?
As you can see when we run this particular.
Method you can see TCP services from
this particular port and the method
that was used was connect method.
Now, let's see which are the hosts that we scanned.
And there comes only one host that is our loopback Network,
which is our home network.
Now, let's see. What is the host name?
So the host name is localhost. If your
scanning any public network, it will
show the host name of that particular IP address.
Now, let's see. What is the state of this particular host?
As we are scanning our local machine.
The loopback IP is up as you can see the host
status.
The state is up.
now
Let's see.
This particular method which is all protocols and
this method Returns the protocol for the
current Network being scanned.
So let me just type this and welcome to know the protocol that
has been scanned for and it is TCP transmission
control protocol.
The next one is the
method which is Keys which will written
all the active ports available within the specified
range that we have given. So let's just
run this and hit enter and you can see two ports
are open one is 80 which we have deliberately opened
by Python and one more Port which is
88, which is also running as open.
All right.
let's
see
further
now let us ask that the port
80 is
running on TCP or not
So, let's see it. Is it running on TCP? Yes.
It is running on TCP in case we were scanning
Port 53, which is the UDP port for DNS.
Then it would have shown false over
here.
Okay, so
let us scan for UDP this time.
Let's type here.
53
And you can see false. Alright because DRS
server runs on a UDP
port.
now
Let us see the details about.
The Local Host
The protocol the port number and we are going to
see the scan details something like this. So, let
me just paste it over here.
And you can see the details wherein we get the product. This
is the details from the SV, which
is the service version detection which happened ago.
We have done it over here.
And you can see simple HTTP server. The state is open. The
version is 0.6 name is httpconf.
As you can see extra information we have got which
is running a python server reason a synac
was sent.
And you can see CPE it is saying simple HTTP server
0.6.
Alright, so
this was how we can scan.
using nmap
python Library
Let us see the last one.
And hit enter and you can see we get the
exact same output.
Because both of them are exactly the same.
So I hope you guys understood how you can use the nmap library
for Python and perform the
same scans without even going into nmap
or running the GUI version just
directly from the python. You can import the
and map and you can start scanning.
I hope everyone of you understood. Thank you.