linux下ping多台机器,扫描多个特定端口
周末被问倒的一个问题,其实就是考基础的shell1.linux下ping多台机器:
建立/tmp/servers
# cat /tmp/servers baidu.comgoogle.comsina.com
建立相关的sh文件
# cat /tmp/mping.sh #!/bin/bashwhile read line #读每行doping $line -c 3#ping特定的host,cout为3done < /tmp/servers
测试结果:
# /tmp/mping.sh PING baidu.com (123.125.114.144) 56(84) bytes of data.64 bytes from 123.125.114.144: icmp_seq=1 ttl=128 time=60.6 ms64 bytes from 123.125.114.144: icmp_seq=2 ttl=128 time=63.1 ms--- baidu.com ping statistics ---3 packets transmitted, 2 received, 33% packet loss, time 1999msrtt min/avg/max/mdev = 60.649/61.923/63.197/1.274 msPING google.com (74.125.71.104) 56(84) bytes of data.64 bytes from hx-in-f104.1e100.net (74.125.71.104): icmp_seq=1 ttl=128 time=158 ms64 bytes from hx-in-f104.1e100.net (74.125.71.104): icmp_seq=2 ttl=128 time=151 ms64 bytes from hx-in-f104.1e100.net (74.125.71.104): icmp_seq=3 ttl=128 time=154 ms--- google.com ping statistics ---3 packets transmitted, 3 received, 0% packet loss, time 2005msrtt min/avg/max/mdev = 151.705/154.733/158.267/2.740 msPING sina.com (12.130.132.30) 56(84) bytes of data.64 bytes from 12.130.132.30: icmp_seq=1 ttl=128 time=225 ms64 bytes from 12.130.132.30: icmp_seq=2 ttl=128 time=233 ms64 bytes from 12.130.132.30: icmp_seq=3 ttl=128 time=224 ms--- sina.com ping statistics ---3 packets transmitted, 3 received, 0% packet loss, time 2013msrtt min/avg/max/mdev = 224.907/227.901/233.778/4.173 ms
2.linux下扫描特定机器端口
建立/tmp/servers_port
$ cat /tmp/servers_port google.com 80baidu.com 8080 #不通的127.0.0.1 22
建立脚本mnc.sh
$ cat /tmp/mnc.sh #!/bin/bashwhile read linedonc -zw1 $line #超时一秒done < /tmp/servers_port
测试结果
# ./mnc.sh Connection to google.com 80 port succeeded!Connection to 127.0.0.1 22 port succeeded!
页:
[1]