Introduction to netstat
Introduction to netstat
If you were going to ask me Mike you only get one networking tool.
Well I'd probably say pitching it but my second choice would be the popular net
stamp program one of the things that happens is that my computer is on a network
right now and actually on the Internet as well.
So there's all these connections going on at all times and I want to know who is my
computer connecting to at any given moment.
It is a text based command that allows you to see what connections are established
between your computer and other computers at any given moment.
So let's run that step to run that stat just get to a command prompt.
First of all these are active connections that we have right now.
Then it says What's our local address which is pretty much always going to be our
own IP address.
The next value is your source port number that's always going to be an ephemeral
port there.
I don't like this so what we're gonna do is we're going to type net stat again.
And when you do net stat dash n what that says is don't put nice words and stuff in
there.
So now it's telling me this is easier for me to read so I can see I've got a number
of other computers out in the world someplace and they're connected on port number
443.
Now the problem that you'll have with net stat when you first get used to it is
that you're not going to know what these port numbers are.
So remember you're going to be the client on this side and you know you're
connecting to this guy on 443.
Well that's where web browsers come into play pretty much guarantee it's my have
this web browser open as why it happened.
So what what's really happening here is my web browsers open and I'm on secure web
sites now.
Just to let you know the browser that I run always will go to a secure Web site so
if I've got a choice at a particular spot to go to a regular web site it will
automatically is a security feature.
Go to HTTPS.
So all that's telling me right there is I've got a bunch of web stuff open.
So over time if I keep running next stat around run it again you'll see that things
have gone from established down to time wait.
So what's basically happening here is that they've been closed but we're waiting
for the time out to kick in.
Now after a while you'll start to notice that sometimes they don't close and that's
where things get a little bit interesting.
So one of the things you're often going to want to do is you're going to say OK
I've got all these programs running but you've got to keep in mind on your end
there is an executable program that's associated with every one of these.
So what I'm going to do is I'm going to run net stat again except this time I'm
going to do the minus B option.
What is neat.
You're not going to be tested on how to set up run as administrator for different
OS but just be aware that that's there.
So it was a good read and stat might just be and it will show us who is making
these connections and right now this looks like to be a Windows connection itself.
So it's still running a little bit we're going to give him a moment.
OK.
So we can see we have a number of connections that we do be and he's seeking can
can donate different options and bunch of stuff shutting down.
So that's good.
All right.
You can type in o now when you type in o what that's going to give you is the
process ID.
Every program that's running on your computer has a process ID so I can hit task
manager
and I can use this to locate the process id that is is actually running that.
1 3 2 8.
So again I've tested this when I know that this is a program that I want to run.
But any time you got something running and you're not sure what it is doing the net
stat o option will give you the process id and then you can actually go into Task
Manager if you have a more recent version of Windows.
And based on the process ID number you can figure out who exactly is doing all this
stuff to you.
For example one of the things is I'm actually running a web server on this
computer.
So I'm going to do a net stat except this time I'm going to do.
I'm going to do any because I like the numbers better than the letters and I'm
going to do a a means show me all active ports even the ones that I don't have
connections on right now.
And you get a big ugly list most of this stuff wait out here has to do with IPV V-6
which will cover in later episodes.
And he said double call and that's IPV six steps.
But as you look through here here all these zillions of open ports you see this
there's nobody connected to it.
These ports are open so you can actually go through and look through all these Most
of this is stuff that comes with Windows for neighbor discovery and things like
that.
But every now and then you'll find something really interesting.
So these these are very powerful tools in terms of helping me watch what's open on
my computer.
You get good at it after a while 135 and for 45 that's naming convention 21 79 is
neighbor discovery and stuff like that.
But when in doubt all you do is go through here and start looking at this stuff to
understand what all of these mean.
line so far.
When you read that stat minus are the shows you your routing table.
So you can actually look at the routing table on your own individual computer just
by typing step minus our this is identical to typing in the command route net stat
is an amazingly powerful tool.
It's by Mark Russinovich with this cist internal site process explorer and TCP view
are two programs and he runs that are absolutely fantastic.
So anyway the important thing for the network plus is to appreciate that net stat
keeps track of all the connections we have.
And it also lets us know our listening ports whenever you run that stat always run
it with the mind is an option.
I like that because I like to see all the different port numbers because that's the
big clue to this.
Anytime you see a connection and you don't know what the port numbers are look it
up.
The netstat command lists all open ports and network connections on a computer
-a -b -n -o -r