[Autogenerated] for this section,
we will be moving back into our demonstration environment and showing how to
interact with a remote DNS server using the DNS python module and how this
information can be used as a network security engineer.
This will include the initial connection examples of output from the
module when targeting specific DNS record types.
As well as a review of some of the different methods
that the DNS python module implements.
Now,
let's move back into our demonstration environment and take a look at how we can
use the DNS python module within Python in order to return a variety of
different DNS record information as noted in the intro.
The DNS python module is quite expansive in its
support of a number of different things,
including everything from simple lookups,
which we're going to mainly reference to initiating zone transfers
and much more extensive DNS collection work.
But for our purposes we're only going to be mainly using it as
a resolve er and showing how it can be used in order to gather
information from a targeted name.
So for this we're going to begin by taking a look just at the
simplest of scripts and at the top end here we can see that we are
importing the DNS dot resolve er module,
which is the DNS Python module that we're talking about and then what we're
going to initially take a look at is the resolve method,
which is shown here actually, we're going to begin off with an a record.
Obviously if you're not familiar with D N S.
Uh some of the different record names will be confusing but I'm
assuming that the vast majority of people who would watch this
module are at least a little bit familiar with the different
types of DNS records that exist.
The primary ones being a or the address record quad for IPv6 address records,
see name for canonical names or domain name,
which is linked with a record Mx, which is the male record.
So that's being used for email redirection and ask for the name servers.
PTR S, which is for pointer record, which is whenever you do a reverse link,
whenever you're mapping an I.
P address to a name and then the S which is the start of
authority record for a specific domain.
So let's start with something really simple.
And we're just going to do an a record look up for google dot com.
And then what we're going to do is return that into the answers variable
and then we're going to display that inside a for loop So simply just
displaying out the information that's returned.
So if we run that script, it'll return these six different I.
P addresses which are linked with the google dot com name.
Obviously google does this in order to ensure that there's multiple devices
that can support the traffic coming in because of the volume,
if you're talking about only a smaller server.
So if we look at my server or my website,
you're gonna get just one record that we're going to see here.
So if we return this to google real quick,
we're gonna walk through the different ways that we
can display this information.
So they have these six different addresses that are returned.
All we're doing with this part of our code is _______ out the information as
it's exists inside that answer is variable but we can also print out that
information a little bit more individualized.
So to do that,
we can comment out these different lines and we can take a
look at some of the different options here.
So the first thing we're going to take a look at is using the queue name,
attribute of the answers variable.
And if we run that we should get the initial query name that we did.
So in this case it returns www dot google dot com.
The other one is the response which is the raw response information
or data that's coming back from the initial query.
So in this case this includes everything including the different flags,
the initial question and then all of the different answers that returned back.
You can also refer to this information in a little bit different format using
the r r set attribute return that it's gonna basically show the back end of
that last output where you see each one of them is sort of in a line by line
record as it would sit in a DNS zones file.
Now each one of these records or lines can be individually referenced.
So if I wanted to do, say we wanted to index it to the index number of four.
We just wanted to kick out that one.
We're showing both here.
So we're going to see that.
So we have the initial six records that click back
as part of the normal response, so that part of it.
And then this is referencing that fifth variable.
So it's only going to return this now.
We can also let's just leave it on the response.
So we see the whole thing, see other records.
So as we noted before, there's a number of these different records.
So if you look at the mx record and we wanted to show
the response for the mx response, Well,
there was an air because there is no air max response
to the dubs dot google dot com,
but there will be an mx response to the google dot com.
So all this information and basically the only thing we
need to focus on here is this line.
So if you're trying to send email to google,
it's automatically going to go to smtp dot google dot com.
And then if we did a look up on that one,
we would see that that's further linked to these five addresses that are
shown here for the purposes of network security using a module like the
DNS python module will allow you to extend your potential range of
information that you can collect about an IP address But all of this
information can be formatted in a way that can be useful from a network
security standpoint,
as it fills in some of the gaps that you would not have if you only had the I.
P.
Addresses or if you only had the hostnames So with that,
let's move on from this demonstration section and into our summary.