Python 3 Programming Tutorial - Threaded port scanner

Python 3 Programming Tutorial - Threaded port scanner


Now that we've seen how to make a simple port scanner in Python 3, we've found that it is quite slow and cumbersome. So here, we tie in our knowledge of the threading module that we learned previously to dramatically improve our performance.

Sample code for this basics series: http://pythonprogramming.net/beginner...

Python 3 Programming tutorial Playlist: http://www.youtube.com/watch?v=oVp1vr...

http://seaofbtc.com
http://sentdex.com
http://hkinsley.com
https://twitter.com/sentdex

Bitcoin donations: 1GV7srgR4NJx4vrk7avCmmVQQrqmv87ty6
Closed Caption:

everybody went into the socket tutorial
video this video is gonna be kind of
building on the last video that were
covering and that was a port scanner and
actually i want to show you guys the
combination of socket and the threading
module which we've already covered the
threading module show you another
example of threading in action so if you
don't remember this was our threading
tutorial here and the actual job that
was being run was actually just time to
sleep 0.5 so it's just an operation of
sleep but as you can see this is very
simple we have a function this example
job . so in theory we should be able
just throw a port scanner right into
example job and that would be it right
so let me move that aside now and we're
going to go ahead i think we'll do is
we'll rewrite most of this just so we
can go over everything one more time and
really rehash got going on so I so going
for socket
we're also going to import threading and
then we're gonna say from Q import q and
then really think we need to import time
for any reason so we're not going to
import a time like we did before and now
we're ready to go we're going to use a
print lock again so was a friend lock
equals reading . capital lock and then
we're going to say our target equals
again
python programming dotnet and now ready
to get started so just like before we
need our port scanner so I'm going to
define port scan and the parameters will
have port then we're going to say s
equals socket . socket and then
parentheses your socket . AF underscore
I neck and then socket . sock stream so
again nothing new so far with sockets
we've already covered with that line
means and now i want to engage in a
trying to accept like we had before and
so we're going to say try con for
connection equals s . connects and then
we want to connect to target comma or a
nice to people here and so we're going
to try to do that and then if that gets
successful they're going to run this
with statement and we say with print
block print poor port is open
ok so we do that and then once we're
done with that we're going to say
conduct clothes and because we want to
close that connection once were finally
done and then accept and then pass so if
it doesn't work we're just going to pass
we're not gonna print out like oh this
is not open or whatever extent we're
just wasting our current statements with
this print lock so that's it for our
port scanner it should look almost
identical to the port scanner that we
built in the previous video so now we're
going to define our threader which
really is going to be exact copy of the
previous threader that we had before so
that's going to be while true and it
will be worker equals Q dot get and then
port scan worker not totally identical I
suppose this was like example job or
scan worker and then finally cute . task
underscore done just as a rehash this is
going to get the worker from the queue
this is going to run the example job
with the worker passing through as the
port numbers so
we specify a range of numbers as workers
so we can also specify them as ports why
not
and then when we're all done we say Q
dot task done to empty out there are you
awesome so then we'll come down here and
we had better to find Q so Q equals q ue
keep arms and now we're ready to create
our workers so to speak how many threads
are we going to run so for now
oh we're going to say we're going to
have also have thirty 30 different
workers so 4x in range 30 so we've got
30 workers we're going to say key equals
reading . thread target equals rudder so
what's happening here threatening .
threads or creating a thread and then
our target for that threatens threader
which does this gets a workers from the
queue so we're using q & threading and
we'll set them to work on port scanning
which is here which we've read in again
all the stuff was covered in its own
right so far we're just combining those
two things so we do what we did already
cover a specific threading tutorial and
we've already covered the port scanner
so sorry for moving too fast if we
aren't check out the previous videos
next tee . Damon equals true because we
wanted to be a demon so it will die when
the main thread guys ante . start which
has to be called after Tina now we don't
really need to be logging like we did
before so we're not going to use the
logging time now we're going to assign
the amount of jobs and so you can think
of the amount of jobs as in the amount
of ports right so we'll say for worker
in range in this time instead of just 30
or 100 or whatever we need to specify
starting point which will be
one and then we'll say 1 201 so we'll
test the first 100 ports and the reason
why we're doing we have to say one is
because port 0 is an invalid port we
can't scan port 0 so anyway moving on
for worker range 1 200 basically I don't
know why it works so finicky like that
but basically it means it will scan port
1 up 2 101 so it really means port 1 200
anyway moving along queued up put worker
so putting that worker to work ok and
then what we want to do is a cute join
so that will wait thread terminates and
that really should be it so hopefully if
you walked through the threading
tutorial with me you can see how we
basically written the same script as we
did with our initial threading tutorial
where the job was just to sleep we
basically replace that with port scan
and that's about it so we just kind of
nest those together so that's kind of
why I wanted to organize the threading
tutorial in the way that I did because
you just replace the function pretty
much with whatever you need to replace
it with so yeah so anyway let's go and
say that same around this if I made any
errors here or if it worked out for us
save run it's been popping up here yep
space cock stream so let's fix that down
to make some errors try again and
immediately we see poor 22news opens
anybody remember how long it took to get
port 22 to show that was open took a
very long time so that was actually very
quick compared to before we actually
showed poor 22 in port 80
well in advance probably wouldn't even
seen it with our original port scanner
yet so anyway that was very quick then
we can continue we could say hey we want
to do 10,000 jobs and we want to have a
hundred threads let's say so we can save
and run that and you can see 2180 world
we we knew about their they're ripping
open immediately
we're going to continue reading through
ports adventure to guess they're
probably a few more ports that are open
how far do we go 10,000 maybe some of
the 9000 will be open
not not quite sure really not sure what
number were on even right now but we'll
see anyway so now we're actually you
know we're using a hundred threads to
port scan so as you can see we can we
could use this to our advantage
threading and B port scanning you know a
lot of ports up at any one time as
compared to the relational port scan
before anyway on if this pops happen to
pop-ups more ports great otherwise I'm
going to start including this video so
that's it with this video in the next
video we're going to be moving away from
port scanning i just wanted to show you
some people port scanning is kind of a
pretty popular topic and involves
sockets it's very basic so it's really
easy to show plus i could measure it
with sockets & threading so i made a
really great example for threading so
just wanted to cover those things the
next ones that will be talking about be
back to more networking purposes sending
and receiving data using you know and
coding and decoding that data so it
works properly so stay tuned for that
you guys have any questions or comments
on this differently than below as always
thank you for watching thanks for all
the support subscriptions in the next
time
no more ports are open

Video Length: 09:36
Uploaded By: sentdex
View Count: 19,809

Related Software Products
Open Ports Scanner
Open Ports Scanner

Published By:
Filesland

Description:
This utility monitors open TCP and UDP ports on your PC. It brings you an enhanced functionality of a similar tool that comes with Windows operating system: netstat. Open Ports Scanner in addition to the ports information available from your operating system, allows you to map an open port to the process running on your PC. You may easily catch spyware, malware and trojans when using this tool. Just search for suspicious TCP connections. You may instantly terminate unwanted connections right ...


Related Videos
NMap 101: Scanning Networks For Open Ports To Access, HakTip 94
NMap 101: Scanning Networks For Open Ports To Access, HakTip 94

NMap can be used to obtain a much more aggressive scan than the ones we have seen so far. It's very simple to do this too, by simply adding the -A command, like this: nmap -A 10.73.31.64 Aggressive scans simply put together some of the most popularly used commands in Nmap, into one command for you to type. It uses commands such as -O, -sC --traceroute and others. We'll go over these in more detail soon. For now, simply know that -O works for operating system detection, and -sC runs ...
Video Length: 08:51
Uploaded By: Hak5
View Count: 54,875

NMAP port scanning tool
NMAP port scanning tool

please use this tool as a security tool only hr / bClosed Caption:/b font color="#CCCCCC"ok this video is intended for my CIS 160/font classicfont color="#CCCCCC" cochise college it's an/font introduction to information systems classfont color="#E5E5E5" but/fontfont color="#CCCCCC" i understand that/fontfont color="#E5E5E5" this being/font on YouTube a lot of other peoplefont color="#CCCCCC" see/fontfont color="#E5E5E5" ...
Video Length: 04:02
Uploaded By: Clyne Namuo
View Count: 46,761

Python 3 Programming Tutorial - Sockets simple port scanner
Python 3 Programming Tutorial - Sockets simple port scanner

In this Python 3 tutorial, we cover using our newly found knowledge on sockets to create a port scanner. It's a pretty slow scanner, but allows us to see it in practice. Sample code for this basics series: http://pythonprogramming.net/beginner... Python 3 Programming tutorial Playlist: http://www.youtube.com/watch?v=oVp1vr... http://seaofbtc.com http://sentdex.com http://hkinsley.com https://twitter.com/sentdex Bitcoin donations: ...
Video Length: 05:08
Uploaded By: sentdex
View Count: 26,578

Netcat 101: Port Scanning in Netcat, Haktip 85
Netcat 101: Port Scanning in Netcat, Haktip 85

Netcat 101: Port Scanning in Netcat! Welcome to HakTip -- the show where we breakdown concepts, tools and techniques for hackers, gurus and IT ninjas. I'm Shannon Morse and today i'm checking out Netcat for port scanning. First off, let's back it up a bit. I got a question at tips@hak5.org that said, "What defines the banner?" so I wanted to clarify it a bit. Last week, we discussed Banner Grabbing with Netcat, which will give you a bit of information about any server or ...
Video Length: 08:29
Uploaded By: Hak5
View Count: 24,618

Visual Basic 2008 Port Scanner + Source Code.avi
Visual Basic 2008 Port Scanner + Source Code.avi

Code: Imports System.Net.Sockets Timer1: TextBox1.Text += 1 Try Dim Range As TcpClient = New TcpClient("127.0.0.1", TextBox1.Text) If Range.Connected = True Then ListBox1.Items.Add(TextBox1.Text & " is Open") End If Catch ex As Exception ListBox1.Items.Add(TextBox1.Text & " is Closed") ListBox1.SelectedIndex = ListBox1.SelectedIndex + 1 End Try
Video Length: 06:40
Uploaded By: hacks1001
View Count: 23,485

How To Scan an IP Range for Open FTP Servers with Angry IP Scanner
How To Scan an IP Range for Open FTP Servers with Angry IP Scanner

[ http://geekblog.tv/1686 ] In this episode of GeekBlogTV, we take a look at Port Scanning for open FTP Servers to see what kind of juicy goodies we can find being given away! We will be using Angry IP Scanner which you can download from http://www.AngryIP.org for free. Angry IP Scanner runs on Windows, Linux and Apple for both 32 and 64 bit on all platforms; you can also compile from source, or fork a distribution by cloning this git repo from sourceforge: ...
Video Length: 03:31
Uploaded By: GEEKBLOGTV
View Count: 19,144

Visual Basic - How To Create A Port Scanner
Visual Basic - How To Create A Port Scanner

In this tutorial I'm going to show you how to create a port scanner in Visual Basic .net this code works incredibly well but is only a foundation base there's many additional features you can add to this function in order to make it more professional and user friendly. Dependent on this videos popularity I will release tutorials in the future on further advancements in this application. Why Scan Ports? Ports need to be opened / forwarded if you're wanting to allow incoming and ...
Video Length: 09:52
Uploaded By: WizzTechCommunity
View Count: 18,659

Copyright © 2025, Ivertech. All rights reserved.