linux下怎么ping多台设备,linux下ping多台机器,扫描多个特定端口

周末被问倒的一个问题,其实就是考基础的shell

1.linux下ping多台机器:

建立/tmp/servers

[root@localhost ~]# cat /tmp/servers

baidu.com

google.com

sina.com

建立相关的sh文件

[root@localhost ~]# cat /tmp/mping.sh

#!/bin/bash

while read line #读每行

do

ping $line -c 3 #ping特定的host,cout为3

done < /tmp/servers

测试结果:

[root@localhost ~]# /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 ms

64 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 1999ms

rtt min/avg/max/mdev = 60.649/61.923/63.197/1.274 ms

PING 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 ms

64 bytes from hx-in-f104.1e100.net (74.125.71.104): icmp_seq=2 ttl=128 time=151 ms

64 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 2005ms

rtt min/avg/max/mdev = 151.705/154.733/158.267/2.740 ms

PING 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 ms

64 bytes from 12.130.132.30: icmp_seq=2 ttl=128 time=233 ms

64 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 2013ms

rtt min/avg/max/mdev = 224.907/227.901/233.778/4.173 ms

2.linux下扫描特定机器端口

建立/tmp/servers_port

[db2inst1@localhost tmp]$ cat /tmp/servers_port

google.com 80

baidu.com 8080 #不通的

127.0.0.1 22

建立脚本mnc.sh

[db2inst1@localhost tmp]$ cat /tmp/mnc.sh

#!/bin/bash

while read line

do

nc -zw1 $line #超时一秒

done < /tmp/servers_port

测试结果

[root@localhost tmp]# ./mnc.sh

Connection to google.com 80 port [tcp/http] succeeded!

Connection to 127.0.0.1 22 port [tcp/ssh] succeeded!

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值