博客
关于我
如何检查多个远程 Linux 系统是否打开了指定端口? | Linux 中国
阅读量:303 次
发布时间:2019-03-03

本文共 2263 字,大约阅读时间需要 7 分钟。

???????? Linux ???????????

?????????????????????????????????????????nc???????????????????????????????????????

?????????????????shell???????????????????

???????????

?????????????????????????????????????????????192.168.1.2??22?????????????????

nc -zv 192.168.1.2 22

?????

  • -z: ??TCP??
  • -v: ??verbose??????
  • 192.168.1.2 22: ??????????

?????????????

  • Connected???????
  • Refused???????

???????????

????????????????????????shell????????????????????????????????

???????

  • server-list.txt???????????IP??
  • port-list.txt????????????
  • ????

    #!/bin/sh# ???????server_list=$(more server-list.txt)# ??????????port_list=$(more port-list.txt)# ?????????????nc??for server in $server_listdo    for port in $port_list    do        echo -en "\033[1mChecking port $port on $server\033[0m"        nc -zv $server $port        echo -en "\033[0m"        if [ $? -ne 0 ]; then            echo "Port $port on $server is closed."        fi    donedone

    ????

  • #!/bin/sh???????/bin/sh??? interpreter?
  • server_list=$(more server-list.txt)??????????IP???
  • port_list=$(more port-list.txt)?????????????
  • for server in $server_list?????????
  • for port in $port_list????????
  • nc -zv $server $port???nc?????????????
  • if [ $? -ne 0 ]?????????????????????
  • echo??????
  • ????

  • ?????port_scan.sh?
  • ??????????
    chmod +x port_scan.sh
  • ?????
    sh port_scan.sh
  • ????

    ?????????

    • server-list.txt?
      192.168.1.2192.168.1.3192.168.1.4
    • port-list.txt?
      2280

    ????????

    Checking port 22 on 192.168.1.2Connected to 192.168.1.2 on port 22Connection to 192.168.1.2 22 closedChecking port 80 on 192.168.1.2Connected to 192.168.1.2 on port 80Connection to 192.168.1.2 80 closedChecking port 22 on 192.168.1.3Connected to 192.168.1.3 on port 22Connection to 192.168.1.3 22 closedChecking port 80 on 192.168.1.3Connected to 192.168.1.3 on port 80Connection to 192.168.1.3 80 closedChecking port 22 on 192.168.1.4Connected to 192.168.1.4 on port 22Connection to 192.168.1.4 22 closedChecking port 80 on 192.168.1.4Connected to 192.168.1.4 on port 80Connection to 192.168.1.4 80 closed

    ??????

    ?????????????80?443?????port-list.txt??????????????

    ??

    • port-list.txt?
      80443

    ???????????????80?443??????

    nc?????

    nc?netcat?????????????????

    • ??????
    • ??????
    • ????
    • ????

    ?????????????? -zv??????????????

    ??

    ?????????shell?????????????????????????????????????????????????????

    转载地址:http://scol.baihongyu.com/

    你可能感兴趣的文章
    Python2中range 和xrange的区别??
    查看>>
    python2和3的区别
    查看>>
    python2和python3的pip版本升级
    查看>>
    python2和python3的区别
    查看>>
    python2备份交换机配置脚本
    查看>>
    Python3 - 在字符串格式化程序参数中使用变量
    查看>>
    Python3 A*寻路算法实现
    查看>>
    python3 grpc安装
    查看>>
    python3 mysql 封装多表_python3 mysql-多表查询
    查看>>
    python3 mysql8_Python MySQL8.0 错误:authentication plugin 'calling_sha2_password' is not supported....
    查看>>
    Python关键代码总览!从Zero到Hero必看的考点
    查看>>
    python3 robotframework+pycharm框架搭建
    查看>>
    Python3 shutil模块
    查看>>
    Python关于strftime函数详细解析 附实战代码
    查看>>
    Python3 tutorial day3
    查看>>
    python3 week4
    查看>>
    Python3 创建数组
    查看>>
    python3 套接字异常(a byte-like object is required not str)
    查看>>
    python3 实现用户三次输入错误记录黑名单并对该用户登录锁定-day1
    查看>>
    python3 文本变图片
    查看>>