zoukankan      html  css  js  c++  java
  • linux-shell系列8 netstat用法

    1 查看TCP连接状态

    netstat -n|awk '{print $6}'|sort|uniq -c|sort -rn

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

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

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

    netstat -n|awk '/^tcp/ {print $NF}'|sort|uniq -c|sort -rn

    netstat -ant|awk '{print $NF}'|grep -v '[a-z]'|sort|uniq -c

    2 查找请求数排前20的IP

    netstat -anlp|grep 80|grep tcp|awk '{print $5}'|awk -F: '{print $1}'|sort|uniq -c|sort -nr|head -n20

    netstat -ant|awk '/:80/ {split($5,ip,":");++A[ip[1]]}END{for(i in A)print A[i],i}'|sort -rn|head -n20

    3 tcpdump嗅探80端口的访问看看谁最高

    tcpdump -i eth0 -tnn dst port 80 -c 100|awk -F"." '{print $1"."$2"."$3"."$4}'|sort|uniq -c|sort -rn|head -n20

    4 查找较多time_wait连接

    netstat -n|grep TIME_WAIT|awk '{print $5}'|sort|uniq -c|sort -rn|head -n20

    5 查找较多的SYN连接

    netstat -n|grep SYN|awk '{print $5}'|awk -F: '{print $1}'|sort|uniq -c|sort -rn|more

    6 根据端口列进程

    netstat -ntlp|grep 80|awk '{print $7}'|cut -d/ -f1

    7查看PHP-cgi进程占用内存总数

    total=0;for i in `ps -C php-fpm -o rss=`;do total=$(($total+$i));done;echo "PHP-CGI Memory usage: $total kb"

  • 相关阅读:
    C# String 与 byte 互转
    ajax 传值 中文乱码问题
    Js 日期处理
    sqlCacheDependency 更新缓存Cache
    SQL分割字符串,返回临时表
    E:could not get lock /var/lib/dpkg/lock -ope
    YAML-CPP
    [gazebo-1] process has died [pid 22855, exit code 255,
    gperftools对程序进行分析
    pclConfig.cmake or PCLConfig.cmake
  • 原文地址:https://www.cnblogs.com/kuku0223/p/8929868.html
Copyright © 2011-2022 走看看