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的所有使用方法都已經基本全部說完了,希望在看了這篇文章的高手當中能幫我指出一些錯誤。
聲明:此文全部內容由iceblood本人收集或原創,版權歸iceblood所有,如要轉載或修改請務必通知我并注明出處,我的E-Mail為
延伸閱讀
文章來源于領測軟件測試網 http://www.kjueaiud.com/