My Third Ever Bash Script

When it comes to learning coding/scripting, I am still quite superficial. I learn only the things that are needed to perform this or that task on the course I am studying, not less, not more.


I know, I have to dig deeper in every single language I need but...


When it comes to changing your career, you feel like you have so much to catch up with, so much to learn. It is often hard to prioritize goals, as you think you might waste your time learning some details of a specific subject, you will never need or use.


However, even though I only learn the things I need to know to complete a specific task, I still do my best to understand, what exactly I am doing and why.


Copy-pasting is for the script kiddos. If you want to become a cybersecurity professional, you have to understand what exactly are you doing, when you write a script/piece of code.


My Third Ever Bash Script


So, this my third ever bash script (an IP Sweeper simple bash script). The first two were just simple math scripts that I made to learn the basics of bash scripting.


This script is made to ping sweep active IP addresses in a network.


This how it looked like in my Nano:

Ping sweep IP address bash script
Ping sweep IP address script

This is the text version of the script:


#!/bin/bash

for IP in `seq 1 254`; do
ping -c 1 $1.$ip | grep "64 bytes" | cut -d " " -f 4 | tr -d ":" &
done

Where:


64 bytes is the keyword

-d - delimiter

“ ” - space (the character we use as a delimiter)

-f - field expression

4 - field (specifying the number of fields)

tr - deleting a character

“:” - the character to delete


Then I had to make the file executable using chmod, and afterward, simply run it using the wished sweep IP address range:


./ipsweep.sh 192.168.1.1

The ping sweep script includes search parameters, a conditional statement, and parsing.


I have learned this thanks to the Full Ethical Hacking course made by lovely @thecybermentor ♥ He is one of the people who inspires the career change so much!

So, this IP address sweep script is quite easy, isn't it? Even if you are not proficient in the bash scripting language, it is not hard to learn what is behind each variable and operator we use.


So, let us talk.


What was the first script you ever written and executed?


Have you ever written the IP address ping sweep script? How different was your execution?