In the actual work, it is often

IP

Conflict can also lead to work congestion, and today I offer you a solution.

(No copying, I will be angry)



First of all,
With the

for

Circulation and
if

statements
To help you understand.

For

cycle

for

Conditional statements

do
The loop body

done
If

There are two kinds of judgment statements

Single decision statement

if
conditions

; then ;

The results of

; fi(

Here,

;

is
The English characters
the

)

Multiple decision statement

if

conditions

then
The execution result

elif

conditions

then
The execution result

else
The execution result

Fi


Ok, let’s get down to business now!!

Create a new

shell

File, edit the following script.



The first line

#! /bin/bash indicates which shell the script is using, since there are many kinds of shells. For example, Bourne

Shell, Korn Shell, Cshell, etc.

The second line
Is a

For loop, set I initially to 1, less than or equal to 254, increment each time. In general, 255 is not recommended, so 254 is used here.

The third line
is

The do statement for the loop

In the fourth row a

If statement

Ping -c 2 10.0.2.${I} >/dev/null
The mean and

10.0.2 Ping for each value of ${I} in the network segment, ping twice.

>/dev/null means to redirect to an empty file. It’s like a recycle bin on Windows. You can also redirect to another file. Do as you please.
The fifth line is the then used with the if statement.
Line 6 is

If, which means that the IP is used if the ping succeeds.

If line 4 executes

If the ping succeeds, it will show that the IP was used.

The seventh row is and

If means the opposite. Ping failed.

Line eight means if

If the ping fails, the IP address is not in use.

Line 9 is

The end of an if statement, indicating the end of the if statement on a line.

The first ten lines is

The end of the DO statement. This is the end of the script.

So we can go with this result

Select unused

ip

“Can be avoided

About the IP conflict.

Of course, I’m redirecting the result to the black hole file. The results are only visible at the time, but if you want to keep them for a long time, redirect them to a file you’re familiar with. For future inquiries.

The command to execute the script begins, pay attention!

The first option is to run the script in the directory

source jcip.sh

Execution Result:

Second: Execute first

su –

and
chmod 777 jcip.sh

Run the script in the directory where the script resides

./jcip.sh





How to choose two ways according to their mood. Same old story. Just be happy.
(

follow your heart

!

)