Ping commands combined with dos batch processing can do a lot of work, especially for the lazy system administrators.
Useful.
I. Basic level: Lan ping command usage
1. Change the basic ping settings.
The ping command must be repeated four times by default, and the wait time is also relatively long. This is suitable for wide area networks,
Determine whether an ip address exists on the LAN. Generally, you only need to ping the ip address once, And the timeout time is
It can be within Ms.
I create a batch pin. bat on my PC to replace the default ping settings:
@ Rem pin. bat Createdby Zheng Xiaohui
@ Ping-n 1-l 16-w 100% 1% 2% 3% 5
This command is much faster than the default ping command, followed by % 1 to accept the command line parameters, which is
The following extended usage preparations.
2. ping by a lazy person in a single CIDR Block
If you are as lazy as I do, you can write the network number of your LAN into the batch processing file p. bat:
@ Rem p. bat Createdby Zheng Xiaohui
Call pin 192.168.1.% 1% 2% 3% 5
For example, if your mail server is 192.168.1.2, you only need to enter p 2.
If you have multiple network segments, you can set a network number in the dos environment variable.
3. ping the ultimate gamer
If your internet connection needs to be checked frequently, you can create a batch file and
The shortcut is placed on the desktop and a shortcut key is defined. In this way, you can watch any job at any time.
To check whether the network is connected, just press a combination key, instead of opening the dos window and entering several commands,
Close this window. (When you suddenly break the network in an online game, you need to determine the speed as quickly as possible.
Can the gateway be pinged)
Here we need to use a trick, that is, the doscommand returns the value % ERRORLEVEL %. When the doscommand is successfully executed, the environmental variable % ERRORLEVEL % will assign a value of 0 and the Failure value is 1. We use this method, let the script find network connection problems step by step.
@ Rem pinggw. bat Createdby Zheng Xiaohui
@ Echo off
Ping-n 1 192.168.1.1 | find "Reply"
Rem if this step is successful, it indicates that the connection to the local gateway is normal.
If % ERRORLEVEL % = 1 goto end
Ping-n 1 202.96.199.failed | find "Reply"
Rem is the DNS of Shanghai Telecom Bureau. If this step is successful, it indicates that the connection to the local ISP is correct.
If % ERRORLEVEL % = 1 goto end
Ping-n 1 www.163.com | find "Reply"
Rem if this step is successful, it indicates that there is no problem with the local ISP and internet connection, and there is no problem with the DNS.
: End
Rem pause
Sleep 2
Exit
Sleep 2: Stop for 2 seconds to make it clear, and exit by yourself. Do not close the window.
Note: sleep is an extended command of the windows2000 resource package. If it is not installed, use pause instead.
2. Common ping command skills for network administrators
1. Entry level: network connection monitoring log
In a project, when the Switch Connection is unstable, it will be interrupted for several minutes at random every day,
To capture this issue, make a batch processing file pingtime. bat with time display:
@ Rem pingtime. bat Createdby Zheng Xiaohui
@ Echo off
Echo "Begin ----------------------------"
Rem time <cr.txt | find "current"
Time/t
Pin % 1% 2% 3% 4% 5 | find "Reply"
Rem sleep 10
The time Command has two versions. You can use the time/t command on windows2000,
On win98, you must create a cr.txt file with only one empty carriage return in the current directory.
Then, a batch file is created to call pingtime. bat cyclically and write logs:
@ Rem pinglog. bat Createdby Zheng Xiaohui
@ Echo off
: Begin
Call pingtime 192.168.1.1> pingtime. log
Goto begin
2. Intermediate: search for all active ip addresses in the current CIDR Block
The lack of a well-managed network (the actual environment of most of us) is often hard to figure out.
How many machines are running or how many ip addresses are in use.
How can I get a list in five minutes? You only need one doscommand:
@ Rem pingall. bat Createdby Zheng Xiaohui
@ For/L % A in (1,1, 254) do pin 192.168.1.% A | find "Reply"> pingall. log
By the way, the Windows DOS command has made a lot of extensions, although it is worse than the unix shell
Many, but some complicated scripts have been done, and there is also a netsh command set in terms of the network, it is worth a good study.
3. abnormal usage: search for all IP addresses/mac tables in the current CIDR Block
Ping An ip address in batches. If reply exists, call the arp-a command to view the ip-mac list in the current arp cache, and use the dos filter command find to find the current target IP address.
@ Rem arplist. bat Createdby Zheng Xiaohui
@ Echo off
Call pin % 1 | find "Reply"> nul
If % ERRORLEVEL % = 0 goto arplist
Goto end
: Arplist
Arp-a | find "% 1"
: End
Then, use a method similar to the previous section to create a subnet IP address loop script to call arplist. bat.
@ Rem arpall. bat Createdby Zheng Xiaohui
@ For/L % A in (254,) do arplist 192.168.1.% A> arpall. log
Note: This script is not perfect. For example, when using 192.168.1.1 to filter the arp table, 192.168.1.1 ** will be output and cannot process the local ip address. Therefore, you need to manually modify it after completing the configuration.