Shell Scripting - Ping Sweep Script

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey guys hackersploit here back again with another video and welcome back to the shell scripting series in this video we're going to be looking at how to create our first uh official working and useful script which is essentially a simple ping sweep script this is probably what i started off with and you know just going over it it brings back a lot of memories because it really makes you understand um you know the advantages of scripting languages and how they can be used uh you know for day-to-day tasks that being said uh the main component of this script is going to be using the loops and that's primarily the reason i had to cover it before i started making uh these videos in regards to creating your own scripts all right all right so essentially the purpose or the function of this script is to ping or you know you can customize the the the ping sweep to whatever you want but its purpose is to ping a set a subnet or a set of ip addresses of your choice and to check whether they are online or not now of course as i said this is really simple to do it on one but what if you had to do it on your entire network what if you had an entire range or a subnet in which you had to scan it of about you know 100 computers and you wanted to perform some diagnosis on them and you wanted to know which one is up and which one is not this is a very important one one that you think you'll never use but uh has helped me a lot anyway so i've created uh the script it's called pink sweep dot shell and i have already created my shebang here and we are ready to go alright so the first thing i'm going to do um is let me let me just add a comment here so i can say simple uh ping sweep uh script all right something just really really simple so i can document these uh and maybe if you want these scripts up on github i can do that as well so you can check them out for yourself all right so that's a simple ping sweep uh script and what we need to do now is we need to ask the we are going to be asking the user to enter a subnet uh and i'll explain what this means so i'm going to say uh please uh enter the uh please enter the subnet um or your subnet or let's just keep it at subnet because you might not be performing this test on your own on your own network so please enter subnet and we're going to read and store this variable in the subnet variable now of course that's really not how you'd go about it but the reason i'm doing this is because i want you to understand exactly what's going on here all right so i'm just gonna have that like that so uh read subnet and now we can get started with our loop so uh remember we are dealing with ip addresses and a range that uh you know you can specify within the script depending on the on on the amount of ip addresses i'll explain how to do this using the sequence uh function that comes in shell scripting so uh we're going to use a loop so we're going to say 4 and we're going to use the variable name ip all right and i'm going to uh you can use when you in a loop you can when you're declaring the the variable inside the loop you can you don't need to specify the exact uh you don't need to use an uppercase specification it really isn't needed but if you want to you can as well sorry so for ip in um and you we can say for ip in uh in the list now in the list this is where uh you would specify the range in terms of the subnet so uh you can have an ip if you're in scanning the entire subnet you're scanning ips from 1 to 254 so we use the sequence the sequence can use characters uh keywords and also numbering which is what we're doing so i'm specifying the sequence of 1 to 2 to 254 okay so the sequence of 1 to 254 and we want to do we essentially now want to ping so we can now start our pinging here so i'm going to say ping now when we talk about pinging the thing people don't understand is if we ping here for example google.com what happens is it will keep on pinging uh google.com recursively okay so what i'm gonna do is i'm just gonna hit ctrl c there and i'm gonna clear that out okay so you you you get what i'm doing so when we talk about pinging if i open the the ping manual here uh and we look for where's the command or the up yeah here uh c the c uh the c count or the c command allows you to specify the amount of times you want to ping so you can see stop after sending count and you specify the the count uh the syntax is quite simple it's count and then the amount of times you want to ping that whole so again something that you can play with as well so uh we're going to specify that so i'm going to say uh the count is going to be one we want to ping each iip address once okay and of course you can customize that if you want now we need to use uh so we're saying ping ah let's see we are saying we want to ping um the we are pinging it once but we've already specified yeah now let me explain what why i have two variables here because you might be saying well why don't i just enter the ip well remember specifying a range so we're going to prompt the user to enter the subnet the subnet is the first three digits or denominations that determine uh the the starting ip denomination and then the subnet being either 1 2 all the way to 10 right so what do i mean by this is what we will prompt the user to enter is the first three digits so for those of you using cisco routers that will be 10.10 point maybe one so you enter that and then the rest here is sequenced from 1 to 24 as i p addresses are okay so i'll show you how that works in a second so uh we we have already said that the first three are going to be in terms of the sub and of course we don't have any error checking because someone can enter the entire subnet but that's not how it's designed okay so we'll say for uh for ip in the uh in the sequence here of 1 to 254 that's the variable ip so we can say uh we specify the the variable subnet dot ip right sub subnet dot ip so that will be the first three digits plus the sequence here from one to one uh from one to 254 so from 192.168.1 0.1 to 192.168.1.254 you get you get what i'm saying and again you can change the sequence here depending on the size of the network um and that's pretty much it i think that's all for now so let's save this and i'm going to launch this so i'm going to say ping sweep uh sorry ping sweep and i'm going to enter all right so you can see now it's prompting the user to enter the subnet so the subnet is the first three so i can say 192.168.1 that's my subnet now it is automatically going to use the sequencing and it's going to ping every address from 1 to 254 even the even though they might not exist all right so i'm going to hit enter and as you can see it started the pinging and there you are now i know for my network uh that my ips start at the 100 range and that's because i i have dhcp enabled and i've customized it like that um you can see that we are not getting any hosts up so what we need to do is uh we can edit this again so i'm going to edit this again and uh we can change my range from 1 to 100 sorry 100 so that will scan ips from 100 to 254 and hopefully that holds up now this might not seem very complicated but if you're a systems administrator or if you are in penetration testing this script allows you to know uh a lot in terms of how or what computers are currently active on the network especially if you're talking about the network the size of again as mentioned entire range or entire subnets okay so i'm gonna hit enter and you can customize the ping sweep to whatever you want now the exciting thing as we'll look in the next video is we'll be looking at how to create our own nmap scanner and customizing it again and also showing you how to output the data okay so let's exit here and let's run that again or actually let me clear my terminal and uh oops sorry my bad um we can run that right now and i'm going to enter the subnet 68.1 i'm gonna hit enter and there you are it's gonna start scanning from the ip182.168.1.100 and that is probably up yes it is did it get uh uh yes it received uh one there we are zero packet loss and uh there we are so it's going through all the ips on my subnet now of course not all of them occupied so it's going to scan and it's going to go through all that might be active now you can see the potential problem here is that uh the data being displayed is really not displayed in a way that we can read very easily so in the next part of set of videos we'll be looking at customizing how data is output to the user and how it can be output in a way that we understand you know whether what's going on here so for example in this case we would like to customize it and print out the ip and display whether a host the host is up or not something like that that being said guys that's going to be it for this video i just really wanted to cover how you can utilize all that we've learned so far and how exciting it really is so uh if you found value in this video please leave a like down below if you have any questions or suggestions let me know in the comment section on my social networks or on my website i'll be sure to get back to you and i'll be seeing you in the next video [Music] peace
Info
Channel: HackerSploit
Views: 39,432
Rating: undefined out of 5
Keywords: hackersploit, hacker exploit, shell scripting, shell scripting for beginners, shell scripting in linux, shell scripting tutorials, shell scripting tutorial edureka, shell scripting windows, shell scripting projects, shell scripting examples, shell scripting tutorial for beginners in bangla, shell scripting crash course, shell scripting tutorial for beginners 1, linux, shell, kali linux, hacking, bash, os, software, bash scripting, bash scripting tutorial
Id: U79cJfDTIrQ
Channel Id: undefined
Length: 10min 31sec (631 seconds)
Published: Tue Aug 28 2018
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.