The 7 major usages of ping command, become great god after reading seconds!

A friend reported that we can talk about the use of the ping command. In fact, we have mentioned some of the use of the command before, but there is not much explanation about the ping command. Generally, we use its basic functions. Today we will take a closer look. Use the ping command in detail.

1. Detailed explanation of basic use of ping

Ping is a very powerful TCP / IP tool in the network. Its main functions are:

1. Used to detect network connectivity and analyze network speed

2. Obtain the server IP based on the domain name

3. According to the TTL value returned by ping, determine the operating system and the number of data packets that the other party passes through the router.

We usually use it to directly ping the ip address to test the network connectivity.

Seven usages of ping command

Such as this, directly ping ip address or gateway, ping will display the above data, some friends may ask, bytes = 32; time <1ms; TTL = 128 what do these mean.

Bytes value: packet size, that is, bytes.

Time value: response time, the smaller the time, the faster you connect to this address.

TTL value: Time To Live, which indicates the time that the DNS record exists on the DNS server. It is a value of the IP protocol packet and tells the router when the packet needs to be discarded. You can roughly determine whether the target system type is Windows series or UNIX / Linux series through the size of the TTL value returned by Ping.

By default, the TTL value of the Linux system is 64 or 255, the TTL value of the WindowsNT / 2000 / XP system is 128, the TTL value of the Windows98 system is 32, and the TTL value of the UNIX host is 255.

Therefore, the general TTL value:

Between 100 ~ 130ms, Windows system;

Between 240 ~ 255ms, UNIX / Linux system.

Of course, our main understanding today is not these, but other references to ping.

In addition to directly pinging the IP address of the network to verify the smoothness and speed of the network, the ping command also has these usages. Pay attention to the WeChat public account: Java technology stack, reply in the background: java, you can get the N latest Java tutorials I have compiled, all are dry goods.

Seven usages of ping command

Second, the use of ping -t

Ping the specified computer without interruption until the administrator interrupts.

Seven usages of ping command

This shows that the computer is connected to the router and the network works well. Next, press and hold Ctrl + c on the keyboard to terminate it and continue to ping. It will stop, and it will summarize how many data packets are running and how many are on and off. The 9 common commands on the network are recommended.

Three, the use of ping -a

ping-a resolves the computer name and NetBios name. You can ping its IP address to resolve the host name.

Seven usages of ping command

Four, the use of ping -n

By default, generally only four data packets are sent. This command can be used to define the number of sent packets, which is very helpful to measure the network speed. For example, I want to test the average return time of sending 10 packets. The fastest time and the slowest time can be obtained through the following:

Seven usages of ping command

From the above, I can know that in the process of sending 10 packets to 47.93.187.142, 10 were returned without loss. Among these 10 packets, the fastest return speed is 32ms, the slowest is 55ms, and the average speed is 37ms . It shows that my network is good.

If for some bad networks, such as the monitoring system is very stagnant, such a test, the returned results may show that a part of it is lost. If more are lost, it means that the network is not good and can be judged intuitively The situation of the network.

Five, the use of ping -l size

-l size: send the data packet of the specified size to the target host.

By default, the size of the packet sent by Windows ping is 32byt, and the maximum can send 65500byt. When the data packet sent at a time is greater than or equal to 65500byt, it may cause the receiver's computer to go down.

Therefore, Microsoft limited this value; this parameter is very powerful in combination with other parameters. For example, an attacker can use the -t parameter to perform a DOS attack. (So ​​it is dangerous, do not easily use it on someone else's computer).

For example: ping -l 65500 -t 211.84.7.46

The IP address will be pinged continuously until it is interrupted by the user with Ctrl + C.

Seven usages of ping command

In this way, it will continue to send data packets with a size of 65500byt to the 211.84.7.46 computer. If you only have one computer, it may have no effect, but if there are many computers, the other party can be completely paralyzed, and the network is seriously blocked. It can be seen that the power is not trivial.

Six, the use of ping -r count

Record the route of the outgoing and return data packets in the "Record route" field, and probe the number of routes passed , but only a maximum of 9 routes can be traced.

ping -n 1 -r 9 202.102.224.25 (send a packet, record up to 9 routes)

Seven usages of ping command

After 9 routes are displayed, you can see the picture above.

The 6 types of ping commands are more commonly used by everyone in the project.

7. Batch Ping network segment

For a network segment with many IP addresses, if a single detection is really troublesome, then we can directly ping the network segment for batch detection. There is a problem with that IP address, which is clear at a glance.

First look at the code, enter directly in the command line window:

for /L %D in (1,1,255) do ping 10.168.1.%D

Modify the IP address segment to the IP address segment you want to check.

Seven usages of ping command

After entering batch commands, it will automatically ping all the IP addresses in the network segment.

So what does this "for / L% D in (1,1,255) do ping 10.168.1.% D" code mean?

This (1,1,255) in the code is the beginning and beginning of the network segment, which is to detect all the ip addresses between the network segments 192.168.1.1 to 192.168.1.255, and increment by 1 each time, directly to the 255 ips from 1 to 255 Until the test is finished.

Author: Pheenet Fei Nite

https://www.toutiao.com/a6783191796659782148

END

Learning materials:

Share a copy of the latest Java architect learning materials

Recent articles:

1. Heavy: Java 14 is officially released!

2. Java 14 pattern matching, very new feature!

3. How big should the database connection pool be?

4. Write your first IDEA plugin from 0!

5. A bloody case caused by the leak of the Druid connection pool!

6. 8 data structures that every programmer must master!

7. The 8 ways of writing the singleton mode are very complete!

8. How to use chase MM to understand 23 design patterns?

9. When I go, my colleague actually stores the password in plain text! ! !

10. Take Taobao as an example to analyze the service architecture of large-scale e-commerce!

There are too many dry goods in the public account. Scan the code to pay attention to the public account of the Java technology stack . Read more.

Click " Read Original " to take you to fly ~

Published 470 original articles · won 1029 · views 1.45 million +

Guess you like

Origin blog.csdn.net/youanyyou/article/details/105283198