How to make batch file for ping ip




















As the script loops through the network machines and dynamically puts together IP addresses generated by the two FOR loops, the results of the Ping command get output to a file called IPScanResults. Notice that the full contents of each ping would have too much extraneous information, so the command does a FIND for ping the response line that contains the keyword Reply and only outputs that line, since that line contains the information we are interested in.

The ping command also limits its run time to milliseconds using the -w syntax since otherwise the script would possibly take too much time to execute. Finally notice that the script logs the start time when it was first run and then outputs this both to the command console and to the log file along with the time that the script finished running. This is useful meta information for you to know on average how long your scan took to run. This script is identical to the pure Ping response logging script in the example above.

The one significant difference is that this script logs a second line of output for each IP address scanned. The second line that the new command in this script will output is the result of the nbtstat command. This is meant to put a descriptive machine name in pace to help you identify what machine each identified IP address actually is.

The nbstat command takes a significant amount of time to run, so this slows down this script considerably. However in my opinion, the value add of getting a machine name is worth the wait. Note that the nbstat command is not completely effective or guaranteed to resolve a name.

However this is unreliable and not guaranteed to work so you will need to judge for yourself its effectiveness for the network that you are taking a look at. I found the following article at TechRepublic article about the nbstat command to be very interesting.

Have a look if you are interested in finding out more about its inner workings. Also, in case you are not getting the results from nbstat that you are expecting, try using a different keyword in the FIND command. Please feel free to write me a note in the comments below. I have written a follow-up article to this article that addresses the issue of non-pingable machines on a network. This article expands on the examples I have described in this post and explains how to increase the accuracy of the machine detection routine.

I specialize in Web application development with a focus on building secure systems, integrating applications, and designing robust database structures.

View all posts by Justin Cooney. I like your first batch file. I was to get my batch to display on the active ip addresses and their names. Here is the script to do the ping with color output results. If it is failed the background color will change to red. We used a self ping for sleep function. The code put it in loop so it will ping continuously. Dear Albin, Really it is useful for monitoring purpose and reduce the stress of monitoring person.

I checked it is working fine Regards, Jain Scaria. I forget to comment one more thing , while we giving the batch file name as ping. Also, please don't delete your post again — OneCricketeer. Show 3 more comments. Active Oldest Votes. John Kens John Kens 1, 1 1 gold badge 8 8 silver badges 27 27 bronze badges.

That is a working batch file as long as the batch file user really enters what this batch code expects from user input. But it is very unsafe and could also do unexpected things even on apparently correct entered strings like Add a comment. The Overflow Blog. Podcast Making Agile work for data science. Stack Gives Back Featured on Meta.



0コメント