Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to check the number of ip connections through awk under linux

2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article introduces the relevant knowledge of "how to check the number of ip connections through awk under linux". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

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

Awk common application series, will be updated all the time! I will summarize some of my code in server management over the years and learn with my friends.

This is the end of the content of "how to check the number of ip connections through awk under linux". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report