• netstat 指令


    netstat 指令将所有的网络端口监听情况进行罗列

    语法  netstat -tuln

    几个常见的服务端口

    例  通过grep 查看端口来获得上面的服务是否开启,并给予提示

      1 #!/bin/bash
      2 #Program:
      3 #       Using netstat and grep to detect WWW,SSH,FTP and Mail service
      4 #History:
      5 #2019-7-29  lsq First release
      6 PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
      7 export PATH
      8 
      9 #tell some action
     10 echo "Now, I will detect your linux server's services !"
     11 echo -e "The www,ftp,ssh,and mail(smtp) will be detect! 
    "
     12 
     13 #start some detect work ,to echo some information
     14 testfile=/dev/shm/netstat_checking.txt
     15 netstat -tuln > ${testfile}
     16 testing=$(grep ":80 " ${testfile})
     17 if [ "${testing}" != "" ]; then
     18         echo "www is running in your system."
     19 fi
     20 
     21 testing=$(grep ":22" ${testfile})
     22 if [ "${testing}" != "" ]; then
     23         echo "SSH is running in your system"
     24 fi
     25 
     26 testing=$(grep ":21" ${testfile})
     27 if [ "${testing}" != "" ]; then
     28         echo "FTP is runing in your system"
     29 fi
     30 
     31 testing=$(grep ":25" ${testfile})
     32 if [ "${testing}" != "" ]; then
     33         echo "Mail is runing in your system"
     34 fi
    
    上面的例子有几个坑,需要注意一下
    第一个 还是空格问题。
    testing=$(grep ":22" ${testfile})
    =号前后没有空格,切记。
    第二个 if [  ] 括号中前后需要有两个空格
    第三个 if中 
    "${testing}" != ""
    !=前后都有空格
    第四个 解析
    上面例子的意思,用netstat -tuln命令将机器所有的服务端口信息保存到/dev/shm/netstat_checking.txt文件中
    然后用grep针对端口进行查找,然后在分类输出。原理比较简单,就是那些坑,要注意,否则容易报错。
     
  • 相关阅读:
    DataList控件部分使用方法
    评教系统——设计的重要性
    2010.7——2011.7年度总结
    Javascript初步
    asp.net天轰穿视频学习总结
    Datatable中对某列求和,三种不同情况下的方法
    DataTable删除多行
    C#语言的结构体布局
    geoserver、openlayers、PostgreSQL 开发环境配置
    字节流和结构体的转换[转]
  • 原文地址:https://www.cnblogs.com/Lonelychampion/p/11263596.html
Copyright © 2020-2023  润新知