找到快捷方式,如果一个端口在所有本地网使用Linux开放 [英] Quick way to find if a port is open in all Local Network using Linux

查看:219
本文介绍了找到快捷方式,如果一个端口在所有本地网使用Linux开放的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从bash脚本我怎么能快速找到一个80端口是否打开/听的服务器上。

在所有工作站上打开后台,但有时秋天,我怎样才能从文件中检查所有文件,如果端口是开放的,我发现了一个方式使用

  NC -zw3 10.101.0.13 80安培;&安培;回声打开||回声封闭

但如何使用它散装从一个文件,我所著的文件如下:

  10.101.0.13; 3333
10.101.0.15; 3334
10.101.0.17; 4143
10.101.0.21; 1445
10.101.0.27; 2443
10.101.0.31; 2445
10.101.0.47; 3443
10.101.0.61; 3445

我要分开,非工作的工作之一,同时也是所有的线。谢谢


解决方案

  

我要分开,非工作的工作之一,同时也是所有的
  行。


您可以通过刚才的文件循环和状态写入相应的文本文件

  SED的/; / /文件|而阅读其他IP

        NC -zw3 $ IP 80安培;&安培;回声$行>> opened.txt ||回声$行>> closed.txt
DONE

如果您想保留 IP; otherstuff 格式,你可以用这个来代替

 而读线

        IP = $(SED的/;.*//'<<<$线)
        NC -zw3 $ IP 80安培;&安培;回声$行>> opened.txt ||回声$行>> closed.txt
完成<文件

From a bash script how can I quickly find out whether a port 80 is open/listening on a server.

On all workstations is opened daemon, but sometimes it fall, how i can check all files from file if port is open, i found a way to use

 nc -zw3 10.101.0.13 80 && echo "opened" || echo "closed"

but how to use it in bulk from a file, my writed file look like:

10.101.0.13; 3333
10.101.0.15; 3334
10.101.0.17; 4143
10.101.0.21; 1445
10.101.0.27; 2443
10.101.0.31; 2445
10.101.0.47; 3443
10.101.0.61; 3445

I have to separate working one from non working, but also with all the line. Thank you

解决方案

I have to separate working one from non working, but also with all the line.

you can just loop through the file, and write the status to corresponding text files

sed 's/;/ /' file | while read ip other
do
        nc -zw3 $ip 80 && echo "$line" >> opened.txt || echo "$line" >> closed.txt
done

If you want to keep the IP; otherstuff format, you can use this one instead

while read line
do
        ip=$(sed 's/;.*//' <<<"$line")
        nc -zw3 $ip 80 && echo "$line" >> opened.txt || echo "$line" >> closed.txt
done < file

这篇关于找到快捷方式,如果一个端口在所有本地网使用Linux开放的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆