How would I create a Batch File for Logging Networking Infor
How would I create a Batch File for Logging Networking Information with the information below?
To assist with troubleshooting network systems, you want to create a batch file that auto- matically runs common command-line tools and logs that information to a text file for review. Include four commands from this chapter and send the output to a text file called caseproject31.txt. The batch file should run with a parameter of an IP address or host name. For example, if you named your batch file case31.bat and you wanted to input 192.168.100.2, you would enter the following command: Case31.bat 192.168.100.2 You need to research running batch files with variables to complete this task.
Solution
requirements: logging network related information by executing a batch file for the given IP address as the input to the batch file.
Batch file is a collection of commands to be executed all at once.
Let us create a batch file in windows operating system.
Open a notepad and type the following commands for the above requirement.
set v1=%1
ping %v1% >> caseproject31.txt
tracert %v1% >> caseproject31.txt
pathping %v1% >> caseproject31.txt
ipconfig /all >> caseproject31.txt
save the file as case31.bat .
open the command prompt and go to the location where u stored the bat file.
then run the batch file using the following command
C:\\user\\desktop>case31 192.168.1.12
where case31 is the name of the batch file, 192.168.1.12 is the ip address of the host for which we have to collect the network information.
%1 refers to the ip address given in the command line.
%1 is assigned to v1
%v1% is used in the windows command, for example ping %v1% will execute the ping command for the given ip address and the result is stored in the caseproject31.txt
in this way, all the commands are executed and results are stored in the text file.
