熱搜:win11繞過硬件限制安裝 一鍵重裝Win10系統(tǒng) 最干凈的u盤啟動盤 真正純凈版的win7系統(tǒng)
時間:2014-12-30 17:51:04 作者:qipeng 來源:系統(tǒng)之家 1. 掃描二維碼隨時看資訊 2. 請使用手機瀏覽器訪問: https://m.xitongzhijia.net/xtjc/20141230/33791.html 手機查看 評論 反饋
實例9:列舉出處于 FIN-WAIT-1狀態(tài)的源端口為 80或者 443,目標網(wǎng)絡(luò)為 193.233.7/24所有 tcp套接字
命令:ss -o state fin-wait-1 ‘( sport = :http or sport = :https )’ dst 193.233.7/24
實例10:用TCP 狀態(tài)過濾Sockets:
命令:
代碼如下:
ss -4 state FILTER-NAME-HERE
ss -6 state FILTER-NAME-HERE
輸出:
代碼如下:
[root@localhost ~]#ss -4 state closing
Recv-Q Send-Q Local Address:Port Peer Address:Port
1 11094 75.126.153.214:http 192.168.10.42:4669
說明:
FILTER-NAME-HERE 可以代表以下任何一個:
代碼如下:
established
syn-sent
syn-recv
fin-wait-1
fin-wait-2
time-wait
closed
close-wait
last-ack
listen
closing
all : 所有以上狀態(tài)
connected : 除了listen and closed的所有狀態(tài)
synchronized :所有已連接的狀態(tài)除了syn-sent
bucket : 顯示狀態(tài)為maintained as minisockets,如:time-wait和syn-recv.
big : 和bucket相反。
實例11:匹配遠程地址和端口號
命令:
代碼如下:
ss dst ADDRESS_PATTERN
ss dst 192.168.1.5
ss dst 192.168.119.113:http
ss dst 192.168.119.113:smtp
ss dst 192.168.119.113:443
輸出:
代碼如下:
。踨oot@localhost ~]# ss dst 192.168.119.113
State Recv-Q Send-Q Local Address:Port Peer Address:Port
ESTAB 0 0 192.168.119.103:16014 192.168.119.113:20229
ESTAB 0 0 192.168.119.103:16014 192.168.119.113:61056
ESTAB 0 0 192.168.119.103:16014 192.168.119.113:61623
ESTAB 0 0 192.168.119.103:16014 192.168.119.113:60924
ESTAB 0 0 192.168.119.103:16050 192.168.119.113:43701
ESTAB 0 0 192.168.119.103:16073 192.168.119.113:32930
ESTAB 0 0 192.168.119.103:16073 192.168.119.113:49318
ESTAB 0 0 192.168.119.103:16014 192.168.119.113:3844
[root@localhost ~]# ss dst 192.168.119.113:http
State Recv-Q Send-Q Local Address:Port Peer Address:Port
。踨oot@localhost ~]# ss dst 192.168.119.113:3844
State Recv-Q Send-Q Local Address:Port Peer Address:Port
ESTAB 0 0 192.168.119.103:16014 192.168.119.113:3844
[root@localhost ~]#
實例12:匹配本地地址和端口號
命令:
代碼如下:
ss src ADDRESS_PATTERN
ss src 192.168.119.103
ss src 192.168.119.103:http
ss src 192.168.119.103:80
ss src 192.168.119.103:smtp
ss src 192.168.119.103:25
輸出:
代碼如下:
。踨oot@localhost ~]# ss src 192.168.119.103:16021
State Recv-Q Send-Q Local Address:Port Peer Address:Port
ESTAB 0 0 192.168.119.103:16021 192.168.119.201:63054
ESTAB 0 0 192.168.119.103:16021 192.168.119.201:62894
ESTAB 0 0 192.168.119.103:16021 192.168.119.201:63055
ESTAB 0 0 192.168.119.103:16021 192.168.119.201:2274
ESTAB 0 0 192.168.119.103:16021 192.168.119.201:44784
ESTAB 0 0 192.168.119.103:16021 192.168.119.201:7233
ESTAB 0 0 192.168.119.103:16021 192.168.119.103:58660
ESTAB 0 0 192.168.119.103:16021 192.168.119.201:44822
ESTAB 0 0 192.168.119.103:16021 10.2.1.206:56737
ESTAB 0 0 192.168.119.103:16021 10.2.1.206:57487
ESTAB 0 0 192.168.119.103:16021 10.2.1.206:56736
ESTAB 0 0 192.168.119.103:16021 10.2.1.206:64652
ESTAB 0 0 192.168.119.103:16021 10.2.1.206:56586
ESTAB 0 0 192.168.119.103:16021 10.2.1.206:64653
ESTAB 0 0 192.168.119.103:16021 10.2.1.206:56587
[root@localhost ~]#
實例13:將本地或者遠程端口和一個數(shù)比較
命令:
代碼如下:
ss dport OP PORT
ss sport OP PORT
輸出:
代碼如下:
。踨oot@localhost ~]# ss sport = :http
。踨oot@localhost ~]# ss dport = :http
。踨oot@localhost ~]# ss dport \》 :1024
。踨oot@localhost ~]# ss sport \》 :1024
。踨oot@localhost ~]# ss sport \《 :32000
。踨oot@localhost ~]# ss sport eq :22
。踨oot@localhost ~]# ss dport != :22
。踨oot@localhost ~]# ss state connected sport = :http
[root@localhost ~]# ss \( sport = :http or sport = :https \)
。踨oot@localhost ~]# ss -o state fin-wait-1 \( sport = :http or sport = :https \) dst 192.168.1/24
說明:
ss dport OP PORT 遠程端口和一個數(shù)比較;ss sport OP PORT 本地端口和一個數(shù)比較。
OP 可以代表以下任意一個:
《= or le : 小于或等于端口號
》= or ge : 大于或等于端口號
== or eq : 等于端口號
。= or ne : 不等于端口號
《 or gt : 小于端口號
》 or lt : 大于端口號
實例14:ss 和 netstat 效率對比
命令:
代碼如下:
time netstat -at
time ss
輸出:
代碼如下:
。踨oot@localhost ~]# time ss
real 0m0.739s
user 0m0.019s
sys 0m0.013s
。踨oot@localhost ~]#
[root@localhost ~]# time netstat -at
real 2m45.907s
user 0m0.063s
sys 0m0.067s
。踨oot@localhost ~]#
說明:
用time 命令分別獲取通過netstat和ss命令獲取程序和概要占用資源所使用的時間。在服務(wù)器連接數(shù)比較多的時候,netstat的效率完全沒法和ss比。
上面就是Linux使用ss命令查看socket狀態(tài)的方法介紹了,本文一共介紹了14個使用ss命令的實例,相信通過這個實例講解,你能對ss命令有一定的了解。
發(fā)表評論
共0條
評論就這些咯,讓大家也知道你的獨特見解
立即評論以上留言僅代表用戶個人觀點,不代表系統(tǒng)之家立場