Jump to content

Hello,

 

I work for the IT department for my school, and I was trying to write a script that will ping all of our computers on campus and if log the computer name if they're online.  I think my logic is right but the syntax is kicking my butt.

 

All of our computers are named josef0000XXXX where the Xs are numbers.  Idk why they are, but they are.

 

here is my code

 

@echo off
echo test
FOR /L %%i IN (1,1,1769) DO
(
    echo test
    IF %%i LSS 10
    (
        set name=josef0000000%%i
        ping %name% && echo %name% >> NiceList.txt
    ) ELSE IF %%i LSS 100
    (
        set name=josef000000%%i
        ping %name% && echo %name% >> NiceList.txt
    ) ELSE IF %%i LSS 1000
    (
        set name=josef00000%%i
        ping %name% && echo %name% >> NiceList.txt
    ) ELSE 
    (
        set name=josef0000%%i
        ping %name% && echo %name% >> NiceList.txt
    )
) 

 

 

When I run this code in the command line, I see the word test one time then it simply says "The syntax of the command is incorrect".  I assume that means there is something wrong with the for loop.  We have 1769 computers and I am trying to ping josef00000001 to josef00001769 and then log the online ones to NiceList.txt

 

P.S. This is my first time posting code on here so don't hate if I did the code tags wrong

Link to comment
https://linustechtips.com/topic/783749-cmd-syntax-issues/
Share on other sites

Link to post
Share on other sites

For this purpose I'd just use this tool: http://angryip.org/download/#windows

It's really handy, you just set the IP range and off it goes, if you increase the amount of threads it can ping hundreds of machines at once :)

Link to comment
https://linustechtips.com/topic/783749-cmd-syntax-issues/#findComment-9878725
Share on other sites

Link to post
Share on other sites

remove the

 

@echo off

 

and it will show you where it is stopping

Main Rig:-

Ryzen 7 3800X | Asus ROG Strix X570-F Gaming | 16GB Team Group Dark Pro 3600Mhz | Corsair MP600 1TB PCIe Gen 4 | Sapphire 5700 XT Pulse | Corsair H115i Platinum | WD Black 1TB | WD Green 4TB | EVGA SuperNOVA G3 650W | Asus TUF GT501 | Samsung C27HG70 1440p 144hz HDR FreeSync 2 | Ubuntu 20.04.2 LTS |

 

Server:-

Intel NUC running Server 2019 + Synology DSM218+ with 2 x 4TB Toshiba NAS Ready HDDs (RAID0)

Link to comment
https://linustechtips.com/topic/783749-cmd-syntax-issues/#findComment-9878727
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×