- In this video, I'm gonna show you
how to create a simple Python script
that discovers all hosts in the local sub-net,
sort of discoverable devices on the local wifi network
or all devices connected to your physical ethernet network.
(upbeat music)
Now, to do this, I'm gonna leverage the power of Scapy,
which supports packet crafting for Python2 and Python3.
This is really powerful software.
I'm gonna show you a simple use case
using the software right now, in other words
using ARP to discover devices in the local sub-net
but I'll show you more powerful examples
using Scapy in later videos.
The script that we're gonna use
simply imports Scapy, imports regular expressions
and then asks the user to enter the range of devices to scan
and using this simple command arp_result,
Scapy arping, IP address range entered.
I can get my Python script to send ARP messages out
into a network and discover all the devices on the network.
So in Kali Linux, LS
I've created this file called lanscan.py.
Nano is a text editor.
So nano lanscan.py.
I've simply copied the script into this file.
So this script is the script that I've just demonstrated.
Now I've put a lot of comments in the script
so it explains every line of the code.
So I won't bore you with it, but essentially
all we doing is importing Scapy and regular expressions.
This can be removed if you don't want it.
We are then making sure
that the user enters a correct IP address range
by using this regular expression.
And then we scan for devices in the network,
a very simple script.
Most of this script is just comments
you need pseudo privileges on Kali to run this.
I'm gonna use Python3 in this example,
Scapy does support Python2
but it's recommended today that you use Python3.
So that's what we're gonna use here.
And I'm gonna run my script.
So we're prompted to enter the sub-net
that we're gonna scan.
I'll open up another terminal and I'll show you
that the IP address for this Linux device is 192.168.1.113.
That's the sub-net that we wanna scan.
Now, I'm actually doing everything on this windows, laptop.
It's connected to the wifi network, but in this example
I'm running Kali within a virtual machine.
So we don't see a wifi network we see ethernet network,
but this is essentially the wifi network
that connects my Kali virtual machine
to the physical network around me.
So I'll put in my sub-net
that's the subnet that I wanna scan
and notice we're prompted to enter the right format.
And then Scapy sends out ARP messages
into the network to discover devices.
These are devices in my local network.
So as an example, it's picked up some Apple computers.
It's picked up Synology NAS's, it's picked up Cisco devices,
it's picked up a Netgear RAIDar
and various other devices in the network.
It's as simple as that.
So if I run that again, notice I can put in the network.
Now you could change the script to automatically
select a network, rather than asking the user to put it in.
But in this example, I'm allowing the user
to put in a specific network.
And once again, it's discovered devices.
Here is a printer as an example.
At the moment we not storing this information
in a text file or in a database
I'll show you that in later videos.
We're gonna be iterating and improving our scripts
and making them more and more powerful.
But just a very simple script showing you
why it's a good idea to learn Python.
Python is one of those scripting languages
that can help you in many, many places.
It can help you with ethical hacking.
It can help you with network automation.
It can help you with just automating stuff on your computer,
help you with data science.
There are many, many use cases.
It's well worth your time learning how to use Python today.
Now, you can use the software on Windows.
You can use this on your Apple Mac
but I prefer running everything within Linux.
So that's what I've done here.
I've demonstrated how to use this on Kali.
Kali Linux contains a whole bunch of tools
but in this example,
we are hopefully gonna be learning Python
and having some fun at the same time.
With that being said, if you liked this video
please consider subscribing to my YouTube channel.
Please consider liking the video
and clicking on the bell to get notifications.
I'm David Bombal wanna wish you all the very best.
(upbeat music)