How to check the number of ip connections through awk under linux
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!