~ $ Day 4: Ping Sweeper

Hey! Day 4…are we picking up speed yet? Today’s focus was on building a super basic and not very strong ping sweeper. In other words this a not a ping sweeper you actually want to use anywhere else other than testing on your own IP…😂

Today’s Objectives:

Build a ping sweeper!

Let’s Build!

**note: I put everything on the desktop for ease of access so if you’re following along that’s where you need to be!**

Let’s start by pinging an IP. Find your IP – you should be able to do that by now – but if not use the ifconfig command or ipconfig (on Windows)

Once you’ve got that…

ping (IP)

Let’s see what happens?

Okay bet, so as you can see when we ping our IP it’s going to give us an endless number of what it pings until we stop with CTRL+C but to make that easier we can just count next time…

eg: ping -c 4 ipaddress

This would return 4.

From there we wrote what we just did to a file called ip2.txt as we will need that when working with our script (our sweeper)

Next we are going to look at what that count gave us and see if there is anything unique about it and we’ll use what’s unique for our sweep!

For this we are going to use the bytes! We’ll look at this using the grep command. Grep helps us search in files for a match. For example if we wanted to find a file with the phrase I like cheese that’s exactly what’s we’d grep.

We’ll start out with cat ip2.txt | grep “64 bytes”

Next up we’re going to grab the IP address so that we can see what IP’s are talking back to us and what IP’s are not…this is the purpose of the ping sweeper!

So we’ll add another pipe (|) which just lets you put a lot of commands on one line!

Next we did a cut.

A cut is where we take (by take I mean remove) a delimiter (or a piece of a line in this case our delimiter is a space “ “ ) to the field (f) of 4.

Confusing? Let’s just see what happens when we hit enter on this command and it’ll all make sense…

We‘ll add a pipe to remove the colon on the end of that IP as well … and we’ll add tr -d “:” (tr is translate)

That’ll give us our IP without a colon!

So now we can send this to a script!

Building A Script:

Let’s build our script…

To start we need a place to put it so we’ll do this:

nano ipsweep2.sh (sh is for shell script!)

FOR ANY SCRIPT WE CREATE YOU HAVE TO DEFINE WHAT YOU’RE RUNNING AT THE TOP.

#!/bin/bash

Next up…we need a for loop! Why? It’s going to help us define what IP we are looking for explicitly!

This part is simple because we pretty much created the majority of our loop in the terminal already (grep, cut, -d…remember?)

Now once we save our script…and try to run it…we’ll find that we don’t have permission! What gives!

Well if we go ahead and look at the files on our desktop using that good ole ls -la you’ll see it’s not green! Which means it’s not executable…no worries…we know how to do that now right?

chmod +x ./ipsweep2.sh

Now let’s run it again…

BOOM! We did it! It’s us! It’s our IP! We did it!

That’s all for today! As always, thanks for taking a byte!

Xo Jazzie!

Published by byte sized babe

making a career change into the IT + Cybersec world through studying and self discipline. I’ve got big goals and I’m here to show others if I can do it so can you. Follow along!

Leave a comment

Design a site like this with WordPress.com
Get started