Python 3 Programming Tutorial - Sockets simple port scanner
Key Takeaways
This video tutorial covers creating a simple port scanner using Python 3 and sockets, demonstrating how to scan ports and determine if they are open or closed.
Full Transcript
Hello everybody and welcome to the second part of verse socket tutorial series. In this video, what I'm going to be showing you guys is a simple what's known as a port scanner. Um, basically what a port scanner is going to do is exactly what it sounds like. It just scans ports and it tells you whether or not the port is open or closed. Now, generally we kind of have an idea of what the lower ports in their situation is going to be. Uh, but you can quickly find out if someone's using something like FTP or if they're using SSH or whatever. And then obviously port 80 will be open um for like websites and stuff, but you can use this on other people's computers or you can even use it on your own computer to find out your own vulnerabilities. Naturally with this uh even though this isn't a very good port scanner, I'm not uh responsible for how you decide to use a port scanner. I'm just showing you um how they work basically. So with that, um, let's go ahead and we'll keep, um, S equals. We'll keep, uh, we don't want to keep the port. We don't need any of the server IP. We're not even going to make this request. We don't need to send any requests and we don't need a result. And we don't need any of this. So, uh, now what we can do here is we can say, uh, define Pcan for define port scan. And we can say the parameter is port. Then we define what s uh define s.connect and then we're going to connect server and then uh to port and we've defined server up here. Finally um what we'll actually what we'll do here is we'll say try and if that works we'll return a true uh except uh return a false. Oops. a false. And so what this is asking basically is we're going to attempt to connect. If we can connect, then we'll make a connection and it's going to return true for us. If we cannot connect, it means the port is not open and it's going to return a false for us. Okay. Um and in fact, uh well, no, we'll leave this up here. You could put any anything up here. You could also allow for like input or something like that. But anyway, and now what we'll do is we'll say 4x in range and we'll say um zero actually we'll say 1 to 26. Okay, so this will test port number one through port number 25 and um then we're going to say if pcan x uh print uh port x is open. So basically what we're doing is we're passing that x value whichever x is in this list of sound like my power almost dropped. That was weird. Anyway, um for X in this list of 1 through 26, um it's going to throw that value through the port parameter of our PCAN function and it's going to test it. And then if Pcan X, so what we're asking here is if true. Um so if PCAN X PCAN X is either returning true or false. So we can ask if true or if false, right? Right. So if Pcan is true, print that port X is open. Otherwise, we have no else statement here. So nothing else will run. So we'll only tell us if that port is open. So let's go ahead and save and run this. Python programming.net. Okay. And it's currently running. We don't really see anything occurring at the moment. Um, and really who knows how long this will take. Uh, in fact, let's go ahead and write a quick print. Um, it's usually like one second to port. So anyway, port X is closed. And then we'll add some exclamation marks to make this easy to see. Save over. Okay. Actually, we saw that port 22 is open right away. So let's let's run this one last time. And so port one is closed, port two is closed, port three is closed. So you can see it's it's very slow. And you know, we could run this through 65,000 ports uh per thing we're searching for. So, obviously, this is not uh the most efficient port scanner. Uh it's pretty poor. So, generally what people do is they will thread their port scanner. So, I thought it'd be kind of neat to show you guys our port 22 is open. Uh to show you guys a threaded port scanner. Um so, you can scan multiple ports at one time. So, that's the next thing I wanted to show you guys is a quick threaded port scanner and then we'll actually get back on our on our on the path of sockets and learn uh some more about sockets. So, anyways, uh stay tuned for that. As always, thanks for watching. Thanks for all the support and subscriptions and until next
Original Description
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-programming-tutorials/
Python 3 Programming tutorial Playlist: http://www.youtube.com/watch?v=oVp1vrfL_w4&feature=share&list=PLQVvvaa0QuDe8XSftW-RAxdo6OmaeL85M
http://seaofbtc.com
http://sentdex.com
http://hkinsley.com
https://twitter.com/sentdex
Bitcoin donations: 1GV7srgR4NJx4vrk7avCmmVQQrqmv87ty6
Watch on YouTube ↗
(saves to browser)
Sign in to unlock AI tutor explanation · ⚡30
Playlist
Uploads from sentdex · sentdex · 0 of 60
← Previous
Next →
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
Matplotlib Python Tutorial Part 1: Basics and your first Graph!
sentdex
Python Encryption Tutorial with PyCrypto
sentdex
Python's Logging Function
sentdex
wxPython Tutorials 1: Making Windows GUIs with Python : Installing + 1st window!
sentdex
wxPython Tutorials 2: Making Windows GUIs with Python: Customizing Window Parameters
sentdex
wxPython Programming Tutorial 3: Menu Bar and Menu Button
sentdex
wxPython Programming Tutorial 4: Panels
sentdex
wxPython Programming Tutorial 5: User Input Saved To Variables
sentdex
wxPython Programming Tutorial 6: Multiple Choice Input
sentdex
wxPython Programming Tutorial 7: Adding Static Text and Colors
sentdex
wxPython Programming Tutorial 8: Custom Button Images
sentdex
wxPython Programming Tutorial 9: Tool Bar Items and Sub Menus!
sentdex
Basic PHP Tutorial 13: Multi-dimensional Array
sentdex
Basic PHP Tutorial 15: Functions and Global Variables
sentdex
Basic PHP Tutorial 12: Associative Array
sentdex
Basic PHP Tutorial 14: Foreach loop
sentdex
Basic PHP Tutorial 16: Include and Require
sentdex
Basic PHP Tutorial 7: Assignment, comparison and Logical operators
sentdex
Basic PHP Tutorial 4: Variables and Comments
sentdex
Basic PHP Tutorial 11: Arrays part 1, basic array
sentdex
Basic PHP Tutorial 6: If else and else if conditionals cont'd
sentdex
Basic PHP Tutorial 1: Intro to PHP
sentdex
Basic PHP Tutorial 3: HTML with PHP
sentdex
Basic PHP Tutorial 9: While Loop
sentdex
Basic PHP Tutorial 10: Switch Statement
sentdex
Basic PHP Tutorial 2: Print and Echo
sentdex
Basic PHP Tutorial 5: If else and else if conditional statements
sentdex
Basic PHP Tutorial 8: Arithmatic Operators: Doing math with php
sentdex
Basic PHP Tutorial 17: User Input Form Example / String Manipulation
sentdex
Basic PHP Tutorial 18: HTML Entities and forms cont'd
sentdex
Basic PHP Tutorial 19: Finding words in strings
sentdex
Basic PHP Programming Tutorial 20: Saving to a File / writing and appending
sentdex
Basic PHP Programming Tutorial 22: Hashing part 2: salting
sentdex
Basic PHP Programming Tutorial 23: Variables in Strings and tokenizing
sentdex
Basic PHP Programming Tutorial 21: MD5 Hashing For Security
sentdex
Basic PHP Programming Tutorial 24: String similarity
sentdex
Basic PHP Programming Tutorial 25: Time and Time stamps
sentdex
Basic PHP Programming Tutorial 26: Die and Exit
sentdex
Basic PHP Programming Tutorial 27: MySQL Databases Part 1
sentdex
Basic PHP Programming Tutorial 28: MySQL Database Part 2: Reading From Database
sentdex
Basic PHP Programming Tutorial 29: MySQL Database Part 3: Inputting Data
sentdex
Basic PHP Programming Tutorial 30: MySQL database in Use
sentdex
Django Tutorial Web Development with Python Part 1: Installing Django
sentdex
Python Tutorial: File Deletion and Folder Deletion / directory deletion
sentdex
Python Tutorial: How to Rename Files and Move Files with Python
sentdex
3D Graphs in Matplotlib for Python: Basic 3D Line
sentdex
3D Plotting in Matplotlib for Python: 3D Scatter Plot
sentdex
3D Charts in Matplotlib for Python: Multiple datasets scatter plot
sentdex
Sikuli Tutorial 1: Visually programming in python!
sentdex
Sikuli Tutorial 2: Program visually in python!
sentdex
Sikuli Tutorial 3: Program visually in python!
sentdex
3D Bar Charts in Python and Matplotlib
sentdex
3D Plane wire frame Graph Chart in Python
sentdex
Raspberry Pi Part 1 Introduction
sentdex
Raspberry Pi Part 8: First Download and Update! (Firmware)
sentdex
Raspberry Pi Part 10: How to set up a Linux Web Server on your Pi
sentdex
Raspberry Pi Part 11: Remote Desktop
sentdex
Twitter Analysis: How to rank a user's influence
sentdex
GPIO Tutorial for Pi Part 2 - Programming the GPIO
sentdex
GPIO Tutorial for Raspberry Pi Part 1 - Setting up
sentdex
More on: AI Workflow Automation
View skill →Related Reads
📰
📰
📰
📰
How I Built a Free Online Image & PDF Processing Platform with Vue 3 + FastAPI
Dev.to · IAMUU
I Built a Free AI-Powered YouTube SEO Toolkit With Zero Budget. Here’s What Actually Happened.
Medium · Startup
How to Create a Second Version of Yourself Inside Obsidian Using AI (Step-by-Step Guide)
Medium · ChatGPT
How to prepare for Spain civil service TIC exam using AI in 2026
Dev.to · David García
🎓
Tutor Explanation
DeepCamp AI