Multiple Command Prompt with Ping request with a single script

Home Forums Scripting General Scripting Multiple Command Prompt with Ping request with a single script

This topic contains 19 replies, has 8 voices, and was last updated by Avatar gfrancis 11 months ago.

Viewing 20 posts - 1 through 20 (of 20 total)
  • Author
    Posts
  • Avatar
    premglitz
    Member
    #144583

    Hi,
    Please help me out to get a script to ping a multiple IP Address.
    That script should open a Multiple Command prompt with Ping Request.

    Thanking you in advance

    -PREM

    Avatar
    Rems
    Moderator
    #227570

    Re: Multiple Command Prompt with Ping request with a single script

    Not sure what exactly you try to achieve.
    And, are you looking for a vbscript or batch or..? and in what way should it fetch the Ip-addreses that are going to be pinged?

    Here a batch

    Code:
    @echo off
    Set “newbox=start cmd /k”

    Set IPs=[COLOR=”Blue”]192.168.1.103 192.168.1.105 192.168.1.107 192.168.1.109[/COLOR]

    For %%* in (%IPs%) do %newbox% PING.exe %%*

    Rems

    Avatar
    premglitz
    Member
    #360697

    Re: Multiple Command Prompt with Ping request with a single script

    Hi Rems,
    Thanks for the Script file.
    Any format file is good for me. It is just to make sure all the network is fine or not.

    Please make the script you send, with an continous ping (-t)

    Which will be more greatfull.

    Thanks
    -PREM

    Avatar
    premglitz
    Member
    #360698

    Re: Multiple Command Prompt with Ping request with a single script

    Hi Rems,
    I got the answer for the same.
    Here we go..,

    @echo off
    Set “newbox=start cmd /k”
    Set IPs=192.168.1.103 192.168.1.105 192.168.1.107 192.168.1.109
    For %%* in (%IPs%) do %newbox% PING.exe %%* -t

    Thank you Rems.

    Regards
    -PREM

    Avatar
    Rems
    Moderator
    #227571

    Re: Multiple Command Prompt with Ping request with a single script

    here is an other sample:

    Code:
    @echo off

    Set IPs=192.168.1.103, 192.168.1.105, 192.168.1.107, 192.168.1.109

    For %%* in (%IPs%) do START “%%*”/MIN/LOW COLOR 72^& PING.exe -t %%*

    Rems

    Avatar
    premglitz
    Member
    #360699

    Re: Multiple Command Prompt with Ping request with a single script

    Hi Rems,
    Thanks for the answer and repy.

    Have a great day…!

    Thanks
    -PREM

    Avatar
    Anonymous
    #368934

    Re: Multiple Command Prompt with Ping request with a single script

    hi good day, :-o

    facing 1 problem to save the -t pings to txt file
    try to play around with the script, however the log not saved, only the files created

    Referring to below script, i add > C:%%*.txt at the end of the script, however the logs not saved. but the txt file for each of the listed IPs created in C drive.

    For %%* in (%IPs%) do %newbox% PING.exe %%* -t > c:%%*.txt

    Avatar
    Rems
    Moderator
    #227626

    Re: Multiple Command Prompt with Ping request with a single script

    easternC;190080 wrote:
    hi good day, :-o

    facing 1 problem to save the -t pings to txt file
    try to play around with the script, however the log not saved, only the files created

    Referring to below script, i add > C:%%*.txt at the end of the script, however the logs not saved. but the txt file for each of the listed IPs created in C drive.

    For %%* in (%IPs%) do %newbox% PING.exe %%* -t > c:%%*.txt

    What your sample does is redirecting the output of the creation of a new box, it does not redirect the output of the statements in that newbox. Use parentheses to group or nest the statements after the &
    (like: %newbox% & (things happening in the box) ).

    @echo off

    Set IPs=192.168.1.103, 192.168.1.105, 192.168.1.107, 192.168.1.109

    For %%* in (%IPs%) do call:pings %%*

    goto:-pings subroutine-
    :pings
    (Set newbox=START “%*”/MIN/LOW COLOR 72)
    %newbox% ^&(^>”c:%*.txt” PING.exe %* -t)
    exit /b 0
    :-pings end of subroutine-[/CODE]

    Rems[CODE]
    @echo off

    Set IPs=192.168.1.103, 192.168.1.105, 192.168.1.107, 192.168.1.109

    For %%* in (%IPs%) do call:pings %%*

    goto:-pings subroutine-
    :pings
    (Set newbox=START “%*”/MIN/LOW COLOR 72)
    %newbox% ^&(^>”c:%*.txt” PING.exe %* -t)
    exit /b 0
    :-pings end of subroutine-[/CODE]

    Rems

    Avatar
    bilmalik
    Member
    #391173

    Hi Rems,
    I do not know about writing a bat file scrip , but every day I have to do monitoring network instead of a server. so I need to ping ip from 1 to 255 and from multiple subnets (My office has many branches & has multiple subnet). Can you help me make a bat file to do that, similar your scrip
    [USER=”68995″]Echo[/USER] off Set “newbox=start cmd /k” Set IPs=192.168.1.103 192.168.1.105 192.168.1.107 192.168.1.109 For %%* in (%IPs%) do %newbox% PING.exe %%* Thanking you Regards Handam

    Avatar
    Rems
    Moderator
    #228465

    Hello Handam,

    Here is an example.
    Three network-ids of 3 octets have been defined in this batch. For the last octet a range from 1 to 255 is used to construct IPv4 addresses.

    Code:
    @goto:begin of batch

    :pinging subroutine
    For %%n in (%NetID%) do For /L %%h in (1,1,255) do PING.exe -n 1 %%n.%%h | find /i “ttl=”
    exit /b 0

    :begin of batch
    [USER=”68995″]Echo[/USER] off
    Set “NetID=[B]192.168.1[/B], [B]192.168.2[/B], [B]192.168.3[/B], [B]192.168.4[/B]”
    > “pingresult.txt” call:pinging

    Avatar
    gfrancis
    Member
    #391660

    Hello Rems,

    I am wanting to run this same batch file, but name each command prompt differently. I was trying to set two variables, one for IPs and one for title but can’t seem to figure it out. Can you just use this same format, but name like 192.168.1.103 Desktop, 192.168.1.105 Firewall, etc

    title= Firewall will name the command prompt Firewall, but I can’t figure out how to incorporate that into this batch..

    [USER=”68995″]Echo[/USER] off
    Set “newbox=start cmd /k”

    Set IPs=192.168.1.103 192.168.1.105 192.168.1.107 192.168.1.109

    For %%* in (%IPs%) do %newbox% PING.exe %%*

    Avatar
    tdk
    Member
    #366936
    Rems;n315953 wrote:
    Re: Multiple Command Prompt with Ping request with a single script

    Not sure what exactly you try to achieve.
    And, are you looking for a vbscript or batch or..? and in what way should it fetch the Ip-addreses that are going to be pinged?

    Here a batch

    Code:
    [USER=”68995″]Echo[/USER] off
    Set “newbox=start cmd /k”

    Set IPs=[COLOR=”Blue”]192.168.1.103 192.168.1.105 192.168.1.107 192.168.1.109[/COLOR]

    For %%* in (%IPs%) do %newbox% PING.exe %%*

    Rems

    hi Rems :-)

    i understand that this post is quite old lolz 8-)

    but i’m interested in it as i’m trying to create a ping using a batch file ..

    hope you can share or give an idea how to ping in command prompt as batch file :?:

    thanks

    Avatar
    wullieb1
    Moderator
    #245778

    Use powershell. q

    Avatar
    tdk
    Member
    #366937
    wullieb1;n517399 wrote:
    Use powershell. q

    hi wullieb1 :)

    sorry but don’t have much background using with powershell :-(

    so i think perhaps i should stick on this ;)

    Avatar
    wullieb1
    Moderator
    #245780

    Ok. What issues are you having?

    PowerShell is something that you will eventually have to learn if you want to keep scripting.

    Avatar
    tdk
    Member
    #366938
    wullieb1;n517452 wrote:
    Ok. What issues are you having?

    PowerShell is something that you will eventually have to learn if you want to keep scripting.

    hi wullieb1 ;) ,

    it’s almost the same but i just add some colors in it that i have created a batch file in which i think i have achieved switching color every after IP address 8-)

    my problem it will completely changed the color of the previous IP address being ping using the now present color-assigned to the current IP address :???:

    i just want is to retain the color of the previous IP address being ping :wine:

    @echo off
    :beginning

    ping -n 7 24.120.201.37

    color 9

    ping -n 7 24.120.201.38

    color 3

    ping -n 7 24.120.201.49

    color 6

    goto beginning

    Avatar
    biggles77
    Spectator
    #214430

    You could try a 10 day free trial of the Pluralsight Powershell tutorials and learn about how to use it that way. It’s worth a look especially with the 10 free days.

    Avatar
    wullieb1
    Moderator
    #245785
    tdk;n517467 wrote:

    hi wullieb1 ;) ,

    it’s almost the same but i just add some colors in it that i have created a batch file in which i think i have achieved switching color every after IP address 8-)

    my problem it will completely changed the color of the previous IP address being ping using the now present color-assigned to the current IP address :???:

    i just want is to retain the color of the previous IP address being ping :wine:

    @echo off
    :beginning

    ping -n 7 24.120.201.37

    color 9

    ping -n 7 24.120.201.38

    color 3

    ping -n 7 24.120.201.49

    color 6

    goto beginning

    There is no native way, that i can find anyway, to achieve this but there is this https://www.codeproject.com/Articles/17033/Add-Colors-to-Batch-Files

    PowerShell would be simpler IMO.

    #Populate the array with the servers on each site
    $Server = ‘192.168.0.1’, ‘192.168.0.2’, ‘192.168.0.3’
    $colour = ‘Red’, ‘Green’, ‘Blue’
    $i = 0

    # Loop through the servers above and ping them to see if they are alive!
    foreach($Comp in $Server){

    if (Test-Connection -ComputerName $Comp -Quiet -Count 2){
    write-host “$Comp is UP” -ForegroundColor $colour[i]
    }
    Else{
    Write-host “$Comp is DOWN” -ForegroundColor Red
    }

    $i = $i + 1
    }[/CODE]

    That’s a generic Test-Connection script that will loop through and check your servers and each server will have a different colour.

    [CODE]#Populate the array with the servers on each site
    $Server = ‘192.168.0.1’, ‘192.168.0.2’, ‘192.168.0.3’
    $colour = ‘Red’, ‘Green’, ‘Blue’
    $i = 0

    # Loop through the servers above and ping them to see if they are alive!
    foreach($Comp in $Server){

    if (Test-Connection -ComputerName $Comp -Quiet -Count 2){
    write-host “$Comp is UP” -ForegroundColor $colour
    }
    Else{
    Write-host “$Comp is DOWN” -ForegroundColor Red
    }

    $i = $i + 1
    }[/CODE]

    That’s a generic Test-Connection script that will loop through and check your servers and each server will have a different colour.

    Avatar
    tdk
    Member
    #366939

    looks like i really have to do it in PowerShell :sad:

    Avatar
    wullieb1
    Moderator
    #245788
    tdk;n517565 wrote:
    looks like i really have to do it in PowerShell :sad:

    Moving forward you’ll need to learn Powershell if you want to stay working with Windows OS’s.

Viewing 20 posts - 1 through 20 (of 20 total)

You must be logged in to reply to this topic.