Responsive Advertisement

In this section, we will be scripting with bash.

This might seem overwhelming at first, but what we will be doing is building an IP sweeper script. Basically, we will write the script that will ping all the IP addresses in the given range and filter out the IPs that responded and save it in a text file. 

          Later we can use this to perform various operations on that IP address. But wait! In this section, we will learn some fundamentals that we will require to write the script, and in the next section, we will get into action.

       Have you written any code before? Do you have previous programming experience? 



If yes, then it will be really beneficial.

If no, don't worry. This section is for you!


Commands that we will use


grep: It is used to search a given file for patterns specified by the user. Basically, grep' lets you enter a pattern of text and then it searches for this pattern within the text that you provide it.

tr: The tr command is used for translating or deleting characters.

cat: cat command allows us to create single or multiple files, the view containing the file, concatenate files, and redirect output in terminal or files.

cut: It is used to extract sections from each line of input usually from a file.

echo: It is used to print anything on the console.

f-else in Bash

If-Else commands are an important part of programming/scripting. They allow us to make some decisions based on some conditions. Above is the syntax of If-Else in Bash. We check for an expression in the if statement, if it turns out to be true, the statements inside it are executed, otherwise, the statements inside the else block are executed.


For Loops

The for loop operates on lists of items. It repeats a set of commands for every item in a list. It is used to iterate over something. Above is the syntax of for loop.


Example:

for var in 0 123456789

do

echo $var

done

Output: It will print numbers from O to 9


  ☛ IP Sweeping Bash Script

Post a Comment

Technology

Responsive Advertisement
Responsive Advertisement