windows下的netstat和nbtstat

我的一些心理话:我写这些文章并不是给高手看的,而是发现现在刚学计算机的人都是从win95或win98的傻瓜模式开始的,然而要真正学会使用计算机, 这些基本命令却是非常重要的,所以我把这些整理在一起,供大家一起学习。同时,由于我水平有限,当中也免不了有一些错误,还请看了我的文章的各位高手多提 意见。

netstat 和nbtstat可以说都是windows 下的网络检测工具,他们的输入形式很相似而且都是需要在安装了tcp/ip协议以后才可以使用的,但两者的功能却不同。首先我们来看看netstat 这个命令:
c:\>netstat -h

displays protocol statistics and current tcp/ip network connections.
显示协议统计和当前的 tcp/ip 网络连接。

netstat [-a] [-e] [-n] [-s] [-p proto] [-r] [interval]

-a displays all connections and listening ports.
显示所有连接和侦听端口。
此命令可以显示出你的计算机当前所开放的所有端口,其中包括tcp端口和udp端口。有经验的管理员会经常的使用它,以此来查看计算机的系统服务是否正常,是否被“黑客”留下后门,木马等。比如说我就有一个习惯,在刚刚装了系统配置好服务器以后我就会运行一下netstat -a看看系统开放了什么端口,并记录下来,以便以后作为参考使用,当发现有不明的端口时就可以及时的做出对策。由于这个参数同时还会显示出当前计算机有什 么人的ip正连接着你的服务器,所以也是一种实时入侵检测工具,如发现有个ip连接着不正常的端口,你也可以及时做出有效对策。示例:
c:\>netstat -a

active connections

proto local address foreign address state
tcp iceblood:ftp iceblood.yofor.com:0 listening
tcp iceblood:telnet iceblood.yofor.com:0 listening
tcp iceblood:smtp iceblood.yofor.com:0 listening
tcp iceblood:http iceblood.yofor.com:0 listening
tcp iceblood:https iceblood.yofor.com:0 listening
………………
tcp iceblood:1171 iceblood.yofor.com:3306 established
tcp iceblood:ms-sql-s iceblood.yofor.com:0 listening
tcp iceblood:3306 iceblood.yofor.com:1171 established
………………
udp iceblood:ms-sql-m *:*
udp iceblood:4000 *:*
udp iceblood:4001 *:*
udp iceblood:4002 *:*
从上面的情况就可以知道我的计算机现在开放的tcp端口有 ftp(21),telnet(23),smtp(25),http(80),https(443),1171连接着自己的 mysql(3306),ms-sql-s(1433),udp端口有ms-sql-m(1433),4000-4002都是我的oicq。:p

-e displays ethernet statistics. this may be combined with the -s option.
显示以太网统计。该参数可以与 -s 选项结合使用。
这个参数正如所说的,将在下面再跟大家说。

-n displays addresses and port numbers in numerical form.
以数字格式显示地址和端口号(而不是尝试查找名称)。
大家如果只输入netstat 的话就会看见如下类似的结果:
c:\>netstat

active connections

proto local address foreign address state
tcp iceblood:1171 iceblood.yofor.com:3306 established
tcp iceblood:3306 iceblood.yofor.com:1171 established
tcp iceblood:1219 202.109.72.40:6667 established
tcp iceblood:3566 server-2:microsoft-ds established
你会发现这些和netstat -a有相同的地方,只不过netstat 可以很清楚的列举出来当前和你连接的所有计算机,在local address和foreign address里你也发现大多数给出的只是计算机netbios名,却还是不知道当前和你连接的ip,但如果你加上-n参数就不同了,示例如下:
c:\>netstat -n

active connections

proto local address foreign address state
tcp 127.0.0.1:1171 127.0.0.1:3306 established
tcp 127.0.0.1:3306 127.0.0.1:1171 established
tcp 192.168.1.21:1219 202.109.72.40:6667 established
tcp 192.168.1.21:3566 192.168.1.3:445 established
tcp 192.168.1.21:3577 202.107.208.187:110 time_wait
tcp 192.168.1.21:3578 192.168.1.24:445 established
看!是不是很明了了?对方的ip全部都出来了。其实-n参数其实也就是告诉netstat 不解析对方计算机的netbios名。


-p proto shows connections for the protocol specified by proto; proto may be tcp or udp. if used with the -s option to display
per-protocol statistics, proto may be tcp, udp, or ip.
显示由 protocol 指定的协议的连接;protocol 可以是 tcp 或 udp。如果与 -s 选项一同使用显示每个协议的统计,protocol 可以是 tcp udp、icmp 或 ip。
这个参数你可以指定查看什么协议的连接状态,比如我想查看当前计算机正在连接的所有tcp端口,示例如下:
c:\>netstat -p tcp

active connections

proto local address foreign address state
tcp iceblood:1171 iceblood.yofor.com:3306 established
tcp iceblood:3306 iceblood.yofor.com:1171 established
tcp iceblood:1219 202.109.72.40:6667 established
…………

-r displays the routing table.
显示路由表的内容。
这个没有特别的,可以输入netstat -r以后自己研究。


-s displays per-protocol statistics. by default, statistics are shown for tcp, udp and ip; the -p option may be used to specify a subset of the default.
显示每个协议的统计。默认情况下,显示 tcp、udp、icmp 和 ip 的统计。-p 选项可以用来指定默认的子集。
这个参数让我们来配合-e来使用。
c:\>netstat -s -e
interface statistics

received sent

bytes 505385542 41745793
unicast packets 150106 150547
non-unicast packets 313008 807
discards 0 0
errors 0 0
unknown protocols 327149

ip statistics

packets received = 379906
received header errors = 0
received address errors = 215043
datagrams forwarded = 0
unknown protocols received = 0
received packets discarded = 0
received packets delivered = 166002
output requests = 151620
routing discards = 0
discarded output packets = 0
output packet no route = 0
reassembly required = 0
reassembly successful = 0
reassembly failures = 0
datagrams successfully fragmented = 0
datagrams failing fragmentation = 0
fragments created = 0

tcp statistics

active opens = 1556
passive opens = 1
failed connection attempts = 4
reset connections = 143
current connections = 4
segments received = 141243
segments sent = 140462
segments retransmitted = 477

udp statistics

datagrams received = 15125
no ports = 9634
receive errors = 0
datagrams sent = 10628
看!嘿嘿!你的网络基本状态都在这里面,比如你接受了多少数据包,多少字节,有多少tcp端口打开,有多少udp端口打开,太丰富了……这些就留给各位高手自己慢慢琢磨去了。

interval redisplays selected statistics, pausing interval seconds between each display. press ctrl+c to stop redisplaying statistics. if omitted, netstat will print the current configuration information once.
重新显示所选的统计,在每次显示之间暂停 interval 秒。按 ctrl+b 停止重新显示统计。如果省略该参数,netstat 将打印一次当前的配置信息。
这个就是自己定义检查网络状况的时间的参数,比如我想每过10秒检查一次我的计算机当前tcp连接的状态你就输入netstat 10 -p tcp这样netstat 就会每过10秒就把你所有的tcp端口检查一次。

好了,netstat 命令的介绍就到此基本完了,其实关键是要看自己怎么去灵活的使用了。我们再来看看nbtstat
c:\>nbtstat
displays protocol statistics and current tcp/ip connections using nbt (netbios over tcp/ip).
该诊断命令使用 nbt(tcp/ip 上的 netbios)显示协议统计和当前 tcp/ip 连接。

nbtstat [ [-a remotename] [-a ip address] [-c] [-n] [-r] [-r] [-rr] [-s] [-s] [interval] ]

-a (adapter status) lists the remote machine's name table given its name
使用远程计算机的名称列出其名称表。
此参数可以通过远程计算机的netbios名来查看他的当前状态。示例
c:\>nbtstat -a iceblood

本地连接:
node ipaddress: [192.168.1.2] scope id: []

netbios remote machine name table

name type status
---------------------------------------------
iceblood <00> unique registered
work <00> group registered
iceblood <20> unique registered
work <1e> group registered
iceblood <03> unique registered
iceblood$ <03> unique registered
liu_iceblood <03> unique registered

mac address = 00-d0-09-52-91-dc
看见了?从上面就可以知道我的计算机当前计算机的netbios名为iceblood属于work组或域,当前有liu_iceblood登陆的该计算机,嘿嘿~全都出来了。当然你也可以把计算机名换为ip也就是netstat -a 192.168.1.21,效果和上面的一样。这就有点像unix/linux的finger了,如果你经常去netstat -a一台nt主机,你也可以收集到一些对方计算机中的用户列表了。

-a (adapter status) lists the remote machine's name table given its ip address.
使用远程计算机的 ip 地址并列出名称表。
这个和-a不同的是就是这个只能使用ip,其实-a就包括了-a的功能了,我也不再介绍。

-c (cache) lists nbt's cache of remote [machine] names and their ip addresses
给定每个名称的 ip 地址并列出 netbios 名称缓存的内容。
这个参数表示的是在你的netbios里缓存的你连接过的计算机的ip。示例:
c:\>nbtstat -c

本地连接:
node ipaddress: [192.168.1.21] scope id: []

netbios remote cache name table

name type host address life [sec]
------------------------------------------------------------
work <20> unique 192.168.1.20 597
从上面就可以知道你刚刚和ip为192.168.1.20的计算机的netbios连接过。而这个命令也提供给了“黑客”在入侵了对方的主机以后 进而入侵到内部网的一个有利的线索。因为netbios的cache里储存的ip是对方已经信任你的计算机的ip。聪明的“黑客”当然也会从这个方便的地 方入手了。

-n lists local netbios names.
列出本地 netbios 名称。
此参数和netstat -a类似,只是这个是检查本地的,如果把netstat -a后面的ip换为自己的就和netstat -n的效果是一样的了。

-r lists names resolved by broadcast and via wins
列出 windows 网络名称解析的名称解析统计。在配置使用 wins 的 windows 2000 计算机上,此选项返回要通过广播或 wins 来解析和注册的名称数。
这个正如上面所说的,列出当前windows 网络名称解析的名称解析统计。

-r purges and reloads the remote cache name table
清除 netbios 名称缓存中的所有名称后,重新装入 lmhosts 文件。
这个参数就是清除netstat -c所能看见的cache里的ip缓存的。

-s lists sessions table with the destination ip addresses
显示客户端和服务器会话,只通过 ip 地址列出远程计算机。
此参数可以查看计算机当前正在会话的netbios。示例:
c:\>nbtstat -s

本地连接:
node ipaddress: [192.168.1.21] scope id: []

netbios connection table

local name state in/out remote host input output

----------------------------------------------------------------------------

iceblood <00> connected out 192.168.1.22 8mb 316kb
iceblood <03> listening
iceblood$ <03> listening
liu_iceblood <03> listening

从上面就可以知道我的计算机现在正在和192.168.1.22进行会话,看得出是在复制文件,而且是从对方往自己的计算机里复制。通过以上参数所看到的信息到了“黑客”的手中也是非常重要的线索了。

-s lists sessions table converting destination ip
显示客户端和服务器会话。尝试将远程计算机 ip 地址转换成使用主机文件的名称。
此参数和-s差不多,只是这个会把对方的netbios名给解析出来。

-rr (releaserefresh) sends name release packets to wins and then, starts refresh
释放在 wins 服务器上注册的 netbios 名称,然后刷新它们的注册。

interval redisplays selected statistics, pausing interval seconds between each display. press ctrl+c to stop redisplaying statistics.
重新显示所选的统计,在每次显示之间暂停 interval 秒。按 ctrl+b 停止重新显示统计。如果省略该参数,netstat 将打印一次当前的配置信息。
此参数和netstat 的一样,nbtstat的是配合-s和-s一起使用的。

好了,netstat 和nbtstat的所有使用方法都已经基本全部说完了,希望在看了这篇文章的高手当中能帮我指出一些错误。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值