Get the App
SLTechnology News&Howtos  ›  Servers  › 

How to check the number of ip connections through awk in linux system

Shulou Source: shulou.com Published: 2022-06-01 23:41:01 10月03日 Update

Today, I will talk to you about how to check the number of ip connections through awk in the linux system. Many people may not know much about it. In order to make you understand better, the editor has summarized the following content for you. I hope you can get something according to this article.

What is Linux system Linux is a free-to-use and free-spread UNIX-like operating system, is a POSIX-based multi-user, multi-task, multi-threaded and multi-CPU operating system, using Linux can run major Unix tools, applications and network protocols.

The code is as follows:

[chengmo@localhost ~] $awk 'BEGIN {

While ("netstat-an" | getline) {

If ($5 ~ / [1-255] /)

{

Split ($5 T1, ":")

Tarr [T1 [1]] + +

}

}

For (k in tarr)

{

Print KJR Tarr [k] | "sort-r-n-k2"

}

};'

$5 is the fifth field of netstat-an. By default, the other party is connected to the ip and the port.

[chengmo@localhost ~] $time awk 'BEGIN {while ("netstat-an" | getline) {if ($5 ~ / [1-255] /) {split ($5 tarr T1, ":"); tarr [T1 [1]] +;}} for (k in tarr) {print kjintarr [k] | "sort-r-n-K2";};};'

211.151.33.14 28

113.65.21.200 14

121.32.89.106 13

60.191.178.230 12

118.133.177.104 12

58.61.152.154 11

219.137.58.20 11

124.117.248.52 11

122.198.80.145 11

222.88.15.138 10

222.44.13.191 10

222.161.47.34 10

221.4.202.210 10

218.79.64.12 10

183.17.92.193 10

120.72.128.254 10

118.118.121.244 10

116.252.38.236 10

113.248.75.44 10

Real 0m1.149s

User 0m0.032s

Sys 0m1.055s

After reading the above, do you have any further understanding of how to check the number of ip connections through awk in the linux system? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.

Tags: System content Zhongtong operating system support freedom code tasks fields each other that is tools tools applications more users knowledge programs ports articles Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno macOS Docker NVidia MySQL Microsoft