Send a ping to each IP on a subnet

后端 未结 13 1265
时光说笑
时光说笑 2020-12-07 10:21

Is there a command line based way to send pings to each computer in a subnet? Like

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

t

13条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-07 10:46

    I came late but here is a little script I made for this purpose that I run in Windows PowerShell. You should be able to copy and paste it into the ISE. This will then run the arp command and save the results into a .txt file and open it in notepad.

    # 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
    

提交回复
热议问题