向子网中的每个IP发送ping测试。

69

有没有基于命令行的方式来向子网中的每台计算机发送ping?类似于

for(int i = 1; i < 254; i++)
    ping(192.168.1.i);

如何强制进行ARP解析?


请检查此博客文章(http://nomius.blogspot.com/2006/06/checking-network-with-bash.html)是否包含您所需的内容。 - Ólafur Waage
6
使用原生的方式,无需第三方工具:for i in $(seq 1 254); do ping -c1 -t 1 192.168.11.$i; done。该命令用于对IP地址范围内的设备进行ping测试,范围为192.168.11.1到192.168.11.254。 - user285594
14个回答

1

我来晚了,但是我为此目的制作了一个小脚本,在Windows PowerShell中运行。您应该能够将其复制粘贴到ISE中。然后,它将运行arp命令并将结果保存到一个.txt文件中,并在记事本中打开。

# Declare Variables
$MyIpAddress
$MyIpAddressLast

# Declare Variable And Get User Inputs
$IpFirstThree=Read-Host 'What is the first three octects of you IP addresses please include the last period?'
$IpStart=Read-Host 'Which IP Address do you want to start with? Include NO periods.'
$IpEnd=Read-Host 'Which IP Address do you want to end with? Include NO periods.'
$SaveMyFilePath=Read-Host 'Enter the file path and name you want for the text file results.'
$PingTries=Read-Host 'Enter the number of times you want to try pinging each address.'

#Run from start ip and ping
#Run the arp -a and output the results to a text file
#Then launch notepad and open the results file
Foreach($MyIpAddressLast in $IpStart..$IpEnd)
{$MyIpAddress=$IpFirstThree+$MyIpAddressLast
    Test-Connection -computername $MyIpAddress -Count $PingTries}
arp -a | Out-File $SaveMyFilePath
notepad.exe $SaveMyFilePath

0
#!/bin/sh

COUNTER=$1

while [ $COUNTER -lt 254 ]
do
 echo $COUNTER
 ping -c 1 192.168.1.$COUNTER | grep 'ms'
 COUNTER=$(( $COUNTER + 1 ))
done

#specify start number like this: ./ping.sh 1
#then run another few instances to cover more ground
#aka one at 1, another at 100, another at 200
#this just finds addresses quicker. will only print ttl info when an address resolves

0

这个脚本在OpenWRT中运行良好。

在一个新文件中放置以下代码,

#!/bin/sh
echo "Online IPs" > out.txt
COUNTER=1

while [ $COUNTER -lt 255 ]
do
 ping $1.$COUNTER -c 1 -w 400 | grep "time" >> out.txt &
 COUNTER=$(( $COUNTER + 1 ))
done
killall ping

设置执行权限并启动

root@r1:/# nping 192.168.1

然后在out.txt文件中查看所有连接的主机


-3
for i in $(seq 1 254); do ping -c1 192.168.11.$i; done

我猜这个答案被踩是因为它缺乏任何解释?还是因为它需要42分钟(在Ubuntu中的标准ping,最坏情况下)才能完成? - pabouk - Ukraine stay strong

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接