Welcome back everyone.
In this lecture we are going to use and map to create a network scan that this network can and will
help us to find host on our local network.
So what we basically want to do in this lecture is to use and map our specificly and my prayer but that
will help us create scripts that can be used later to identify different networks based on our IP address.
So let's start with it.
So the first thing we need is an map library.
So if you go to get some dot com just search and map go along you will see a link on any map.
So this is an map map or a map provided for and map in Googling.
So this is basically deployed in google link.
So what you can do is that you can use this mapper to create your own sphere based on any map.
So in this lecture we will do this process.
We will take you use this library and then use this library to create our own script which identifies
different devices or whatever network.
So the first thing is to install this package on our local BCE to do this.
Just copy and simply copy the link of this which starts from here.
That is your time dot com slash or love code or whatever the name is and then slash and map and then
go to the terminal and write go get and then paste the link.
So what this command will do is that it will install this library on your own net on your local P.C.
and then you can use this library to create your own sphere.
So us start and then click.
I have already installed this library so there is nothing that you say but a you will have different
progress going on they need to ensure that this package is being installed.
Once this package is done this package is available to your local eco system and it can be used to create
scripts.
So let's start creating streets.
So the first thing we need is that we need to define our target IP address for which you want to search
for devices.
So in this case I'm going to find devices over my local network.
So I'm going to define my target as my local network.
So I'm going to create a new variable called target IP and then I'm going to define the IP address.
So it would give online to not wanting to hold on to your dot com funds slash 24.
So I'm going to define the whole subnet which I'm going to search for IP addresses.
Okay.
Once we have that we can use the library that we just don't need to create a scanner that will help
us scan the devices on our network.
So let's create a new scanner.
So to do this you have to write and map dot News Canada and you can see that there is an automatic import
here.
We just can't get up on on cut slash and map.
So now we can use this method to create an MRI scan that which can then be used to identify devices.
So once you have that you can have to see which arguments it took sides.
So the first hour argument that it requires is a target IP but in according to this library standard
there is like a certain way for which you should give the inputs.
You can't directly write for example target IP and then expect to see a correct result.
So you have to wrap everything in and map so to do this you have to write and my dad would target and
then you have to write the target IP here.
So this is the first element that you have to be different.
So first when you have initialized the target the next step is to find out which ports you want to search.
So similarly in map dot width boards with boards and then you have to define ports.
I'm going to use the very commonly used ports which are etched GDP in the studio.
Yes.
So the port numbers for these ports are 80 and I think the 440.
So now you have two boards.
Now you a net our target and then the ports that we want to scan once we have that we need to define
their time of so that our program doesn't run indefinitely.
So in order to define a time out go ahead.
According to this library these standards you have to define a certain contacts for time out.
So to do this you have to define and mapped out vague contracts.
This context requires the context element if you open the documentation.
You can see that it requires contacts not context.
So first we have to create an object of type context and then you can input this object here.
So let's go over here and define the context.
I'm going to call it the x.
Once you have that C D X you can call it contact Dot.
I know since if you want to set a timeout for our program once we have that you can open this documentation
and you can further see that it requires two elements.
First is the parent context and the second is timeout.
So first define timeout let's say you want to have a timeout for one minute.
So I'm going to call it one could ask kind of minute.
So now we have a timeout defined.
Now we should also define the first element which is let's go here which is the parent context.
So in and then according to this liability the context for a player for a parent is context the background.
So now you have this that the two elements which is context and background and the time out for which
you want to run.
So there is and if I know what a way it says assignment Mitra mismatch.
So it returns an added to if there is no proper contacts.
So I'm going to call it.
It's not an ad and actually it's called the cancel object if you hover over there you can see that it
returns a contact and then it is done that cancel function cancel function is used for cancelling the
uh operations if timeout occurs.
So you have to write deferred and then cancel.
So what this process does is when timeout occurs you turn this by function and then it handles all the
execution properly.
Now once we have this update PDX we can give the symbolic subject here and now everything looks complete.
Now this camera should be stored in some object I'm going to call it scanner and then it also returns
an error.
So first firstly handle ETA if that is not equal to men logged into
those
okay.
Once we have handled the error of our next step is to use this scanner.
So to use this can I simply you can you can call it scanner or front to run the scanner in the scanner
returns to elements.
The first one is that is out of scan.
The second one is the warnings.
And the third one is the error.
So I can use adverbs and link here.
The next step is widening.
I can do the same for widening.
I just have to replace error with one here
and I'm going to use force sent us here and then we're going to use it unless uh
backslash.
Okay now you've handled warnings and arrows properly.
The next step is to use this results to find out what our host our devices are.
So if you hold over it it doesn't get done properly but if you click over here you can see that it returns
to the elements.
The first one is the result which is of type run and then the warnings and then the error.
Now we have to use this design function.
It's a type of struct so and it has a list of hosts.
So this is the element that we are interested in.
So the result contains there is a host object a list of host and we are interesting in this host.
So what we want to do is that we want to loop over this desert start host so I can start a for loop
for our host because to change is a start host so now you have a list of hosts and we can select a home
we can select host to our data over each a host.
So the first check we should perform here is to check if the if the number of hosts are greater than
zero or not.
And if they're not we can simply pass out.
We can simply continue the loop of skipping a loop.
So let's put a check here if none of those dark thoughts
you can liquids to zero or
S
or length of host the dress is equal equals to zero
we can just continue the loop and we don't want to see anything if that this is not this.
Then we can simply print out the host addresses and there goes funding ports.
So I'm going to use a print statement here and then instead of printable and I'm going to use an F and
then I'm going to put in the S Q In this case and then IP and whatever host thought that.
So the IP address is stored in the first element and the MAC address is stored in the second element
but in some cases we don't have every in every case we won't have this MAC address.
So we have to put a check here.
For example if len of
course dot addresses is more than one then we can also print out the MAC address and f
first send us the
host
addresses and one.
So this is how you can print out the host and addresses.
Let's run this and see what happens
go on you and
it's okay.
First let's open this internal then go.
B.
So if you run as you can see that now it's scanning once it's a complete scanning wait I'm going to
put a new line character here so it's more readable
strongly again.
And now you can see that we have a different post and the associate didn't make addresses here.
So this is how you can get and scan your network and find out the corresponding IP addresses and their
MAC addresses respectively so that's it for this lecture.