• 获取连接状态数的awk数组命令


    awk -n|more

    zhutianpeng@ztp-OptiPlex-780:~/Icpp/server$ netstat -n|more
    激活Internet连接 (w/o 服务器)
    Proto Recv-Q Send-Q Local Address           Foreign Address         State      
    tcp       28      0 10.8.0.171:43313        91.189.92.10:443        CLOSE_WAIT 
    tcp        0      0 10.8.0.171:37374        116.213.120.232:80      ESTABLISHED
    tcp       28      0 10.8.0.171:49282        91.189.92.23:443        CLOSE_WAIT 
    tcp       28      0 10.8.0.171:34473        91.189.92.11:443        CLOSE_WAIT 
    tcp       28      0 10.8.0.171:49286        91.189.92.23:443        CLOSE_WAIT 
    tcp        0      0 10.8.0.171:36005        115.182.41.173:80       ESTABLISHED
    tcp       28      0 10.8.0.171:43473        91.189.92.10:443        CLOSE_WAIT 
    tcp       28      0 10.8.0.171:49284        91.189.92.23:443        CLOSE_WAIT 
    tcp       28      0 10.8.0.171:34313        91.189.92.24:443        CLOSE_WAIT 
    tcp       28      0 10.8.0.171:34315        91.189.92.24:443        CLOSE_WAIT 
    tcp       28      0 10.8.0.171:49280        91.189.92.23:443        CLOSE_WAIT 
    tcp       28      0 10.8.0.171:34471        91.189.92.11:443        CLOSE_WAIT 
    tcp       28      0 10.8.0.171:43310        91.189.92.10:443        CLOSE_WAIT 
    tcp       28      0 10.8.0.171:34317        91.189.92.24:443        CLOSE_WAIT 
    tcp       28      0 10.8.0.171:34468        91.189.92.11:443        CLOSE_WAIT 
    tcp       28      0 10.8.0.171:43311        91.189.92.10:443        CLOSE_WAIT 
    tcp        0      0 10.8.0.171:24800        10.8.0.219:49201        ESTABLISHED
    tcp       28      0 10.8.0.171:34319        91.189.92.24:443        CLOSE_WAIT 
    tcp6       1      0 ::1:42019               ::1:631                 CLOSE_WAIT 
    udp        0      0 127.0.0.1:54875         127.0.1.1:53            ESTABLISHED
    提示:实际执行这条命令的时候,可能会得到上万条类似的记录,我们只取若干来举例。

    awk数组获得连接数:

    netstat -n|awk '/^tcp/{++S[$NF]}END{for(a in S)print a," "S[a]}'

    参考:http://oldboy.blog.51cto.com/2561410/1184165

  • 相关阅读:
    《剑指offer》39题—数组中出现次数超过一半的数字
    常见排序算法实现
    剑指offer题目分类
    腾讯2019实习面试题
    Word2vec资料
    Hello World投票以太坊Dapp教程-Part1
    以太坊开发框架Truffle学习笔记
    linux查看端口进程占用情况
    重置fedora root密码
    docker挂载本地目录的方法总结
  • 原文地址:https://www.cnblogs.com/zhutianpeng/p/4248246.html
Copyright © 2020-2023  润新知