天天看點

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的所有使用方法都已經基本全部說完了,希望在看了這篇文章的高手當中能幫我指出一些錯誤。

繼續閱讀