网络基本命令-Netstat

上一篇 / 下一篇  2009-03-25 11:53:08 / 个人分类:网络

一.基础知识
netstat:观察网络连接状态的实用工具
Netstat网络命令可以显示当前正在活动的网络连接的详细信息, 例如可以显示以太网的统计信息、显示所有协议的使用状态,这些协议包括TCP协议、UDP协议以及IP协议等、路由表和网络接口信息,可以让用户得知目前 总共有哪些网络连接正在运行。网上可以看到很多如X-netstat之类的工具,无非其界面为win界面,比较直观些,其功能与此命令差不多去。
usage:Displays protocol statistics and current TCP/IP network connections..(显示协议与当前网络连接)

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

-a Displays all connections and listening ports.(显示所有连接和侦听端口)
-e Displays Ethernet statistics. This may be combined with the -s option.(显示以太网统计信息,可以与-s连用)
-n Displays addresses and port numbers in numerical form.(在数字表里显示地址和端口号)
-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)
-r Displays the routing table.(显示路由表信息)
-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 选项可以用来指定默认的子集)
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+C 停止重新显示统计。如果省略该参数,netstat 将打印一次当前的配置信息)

二.实例
1.查看当前网络连接状况
C:\>netstat /a

Active Connections
(端口类型)(本地地址) (外部地址) (状态)
Proto Local Address Foreign Address State
TCP adsl1688:telnet adsl1688:0 LISTENING 【端口类型 TCP 端口 Telnet 监听状态】
TCP adsl1688:epmap adsl1688:0 LISTENING
TCP adsl1688:microsoft-ds adsl1688:0 LISTENING
TCP adsl1688:1025 adsl1688:0 LISTENING
TCP adsl1688:1027 adsl1688:0 LISTENING 【端口类型 TCP 端口 1027 监听状态】

TCP adsl1688:1131 adsl1688:0 LISTENING
…………………………………………

UDP adsl1688:epmap *:*
UDP adsl1688:microsoft-ds *:*
UDP adsl1688:1026 *:* 【端口类型 UDP 端口 1026】
…………………………………………
用 此参数可以清楚显示出你的计算机当前所开放的所有端口,其中包括TCP端口和UDP端口。我们可以经常的使用此参数,以此来查看计算机的系统服务是否正 常,是否被“黑客”留下后门,木马等。我觉得我们应该有这么一个习惯,在刚刚装了系统配置好服务器以后我就会运行一下netstat -a看看系统开放了什么端口,并记录下来,以便以后作为参考使用,当发现有不明的端口时就可以及时的做出对策。由于这个参数同时还会显示出当前计算机有什 么人的IP正连接着你的服务器,所以也是一种实时入侵检测工具,如发现有个IP连接着不正常的端口,你也可以及时做出有效对策。

C:\> Netstat -n -a

Active Connections 【活动的连接】

TCP 192.168.0.1:139 0.0.0.0:0 LISTENING
……
TCP 218.76.6.122:139 0.0.0.0:0 LISTENING
TCP 218.76.6.122:3038 61.186.175.113:2887 ESTABLISHED 【现在就可以很清楚的看见IP地址和端口名了】
UDP 0.0.0.0:135 *:*
…………………………………… .
2.查看以太网统计信息
C:\>netstat -e -a
Interface Statistics(通信数据统计)

Received【收到的】 Sent【发送的】

Bytes 4054478 717225
Unicast packets 7804 6158
Non-unicast packets 283 286
Discards 0 0
Errors 0 0
Unknown protocols【未知协议】 1564

3.查看路由信息

C:\>netstat -r

Route Table【路由表】
===========================================================================
Interface List【接口列表】
……………………………………
===========================================================================
Active Routes:【活动路由】
Network Destination【主机】 Netmask【子网掩码】 Gateway【网关】 Interface【接口】 Metric【跳数】
(关于Metric来源于几何的距量,我们用它来定义两router之间的距离(或称为Cost),计算计算公式为 10的8次方 / 速度(bps),也就是说,带宽越大的线路線路其Metric越小,可视为距离越近。谢谢坛主NeeKol的教导)

………………………………………………
Default Gateway:【缺省网关】 218.76.6.122
===========================================================================
Persistent Routes:
None
LISTENING 【端口类型 TCP 端口 1027 监听状态】

TCP adsl1688:1131 a

TAG: netstat Netstat

 

评分:0

我来说两句

我的栏目

日历

« 2024-04-20  
 123456
78910111213
14151617181920
21222324252627
282930    

我的存档

数据统计

  • 访问量: 5082
  • 日志数: 9
  • 建立时间: 2009-03-24
  • 更新时间: 2009-03-25

RSS订阅

Open Toolbar