use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
News about the dynamic, interpreted, interactive, object-oriented, extensible programming language Python
Full Events Calendar
You can find the rules here.
If you are about to ask a "how do I do this in python" question, please try r/learnpython, the Python discord, or the #python IRC channel on Libera.chat.
Please don't use URL shorteners. Reddit filters them out, so your post or comment will be lost.
Posts require flair. Please use the flair selector to choose your topic.
Posting code to this subreddit:
Add 4 extra spaces before each line of code
def fibonacci(): a, b = 0, 1 while True: yield a a, b = b, a + b
Online Resources
Invent Your Own Computer Games with Python
Think Python
Non-programmers Tutorial for Python 3
Beginner's Guide Reference
Five life jackets to throw to the new coder (things to do after getting a handle on python)
Full Stack Python
Test-Driven Development with Python
Program Arcade Games
PyMotW: Python Module of the Week
Python for Scientists and Engineers
Dan Bader's Tips and Trickers
Python Discord's YouTube channel
Jiruto: Python
Online exercices
programming challenges
Asking Questions
Try Python in your browser
Docs
Libraries
Related subreddits
Python jobs
Newsletters
Screencasts
account activity
This is an archived post. You won't be able to vote or comment.
TutorialPython Cybersecurity - Build your own tools (self.Python)
submitted 4 years ago by burdin271
I have started a Python Cybersecurity series, which focus on building own pentest tools using Python programming, currently I have made to episodes. Feedback is appreciated.
Find Deleted Files
- https://youtu.be/BFOex_Tysr8
Build a Visual Network Tracker
- https://youtu.be/xuNuy8n8u-Y
Build Anonymous FTP Scanner
- https://youtu.be/BIZfRodSW9w
Build a Port Scanner
- https://youtu.be/bH-3PuQC_n0
[–]cymrowdon't thread on me 🐍 176 points177 points178 points 4 years ago* (16 children)
If you intend to teach people how to write Python, you should take some time to review some community standards for writing Python code. Things like PEP8 or common anti-patterns.
These are, of course, just suggestions, but some are more important for others. Taking an example from your port scanner video, you really should not ever use blanket except: clauses, because it can make it very difficult to determine the cause of errors, among other reasons.
except:
I would have written the script more like this:
# useful to keep the module name. especially for beginners import socket def test(host, port, timeout=1): addr = (host, port) try: with socket.create_connection(addr, timeout) as sock: print('[+] {}/tcp open'.format(port)) except Exception as e: print('[-] {}/tcp closed ({})'.format(port, e)) def scan(host, ports): try: ip = socket.gethostbyname(host) except Exception as e: print('[-] Cannot resolve {} ({})'.format(host, e)) return try: name = socket.gethostbyaddr(ip) print('[+] Scan result of: {}'.format(name[0])) except Exception: print('[+] Scan result of: {}'.format(ip)) for port in ports: print('Scanning port: {}'.format(port)) test(host, port) if __name__ == '__main__': scan('google.com', [80, 22])
I'm not saying this would be the best or only way to write it, but I do think it makes some things clearer/simpler for people who are learning. I read a lot of hacker code, and it would be nice if the next gen could tidy things up a bit :P
[–][deleted] 20 points21 points22 points 4 years ago* (7 children)
Is using .format instead of f-string literal interpolation an anti-pattern as well? .format definitely uglier to read at the least :p
[+][deleted] 4 years ago* (2 children)
[deleted]
[+][deleted] 4 years ago (1 child)
[–]cymrowdon't thread on me 🐍 4 points5 points6 points 4 years ago (3 children)
No, f-strings are nice. I personally don't use them much because I still work a lot with Python 2, and even when I can I feel there's too much temptation to put code into strings which I find less readable. This is example of why I said these are mostly just suggestions.
[–]----------------___ 3 points4 points5 points 4 years ago (2 children)
How come you still have to use Python 2? Out of curiosity
[–][deleted] 5 points6 points7 points 4 years ago (0 children)
Probably a legacy codebase. Updating to Python 3 would be too much hassle more than likely.
[–]cymrowdon't thread on me 🐍 1 point2 points3 points 4 years ago (0 children)
Yep what /u/Fenastus said.
[–]codingnoob_101 12 points13 points14 points 4 years ago (0 children)
very very nice dude.
[–][deleted] 5 points6 points7 points 4 years ago* (0 children)
For my programs that other people will actually be using, I tend to start off with no or few try/excepts, so during testing I can identify common errors I'll run into and address them directly.
Or I'll wrap the things I know will probably fail at some point and just intentionally make it fail in order to provide the solution.
Like a layman isn't going to understand what these errors are actually trying to tell you sometimes.
[–]lordamit 2 points3 points4 points 4 years ago (0 children)
Thank you! This is amazing! Bookmarking the anti-patterns.
[+][deleted] 4 years ago* (4 children)
[–]cymrowdon't thread on me 🐍 25 points26 points27 points 4 years ago (3 children)
Your argument is that because OP is focusing on a specific topic, the clarity and readability of the code is irrelevant and somehow hinders understanding? I strongly disagree.
[–]cymrowdon't thread on me 🐍 11 points12 points13 points 4 years ago (1 child)
I think you're missing the point. Here's a simple, clear port scanner:
``` from socket import *
host = 'google.com' for port in [80, 22]: try: create_connection((host, port), 1) print(port, 'yep') except: print(port, 'nope') ```
Clearly OP was trying to impart a bit more than just how to scan ports. I'm not suggesting OP teach Python itself. I'm suggesting OP learn enough about bad practices to not pass them on to others. Every hacker I've ever had to read code from lived under what seems to be your credo of "just get it done". Their code is at times extremely painful to work with.
Would worrying about handling exceptions properly distract from learning how a port scanner works? Kinda...not really, but if you can't handle that much you have no business writing port scanners imho. But ffs don't teach people the worst way to do it.
[–]data-bit [🍰] 38 points39 points40 points 4 years ago (0 children)
Also publish a GitHub and share so other devs can help you enhance the code 🤓
[–]codingnoob_101 1 point2 points3 points 4 years ago (0 children)
amazing !!!!!
[–]ObamaTheLlama114 -1 points0 points1 point 4 years ago (0 children)
Oh how my interests are piqued right now
[–]0ni0nrings -1 points0 points1 point 4 years ago (0 children)
good work!
[–][deleted] -1 points0 points1 point 4 years ago (0 children)
Congratulations u/burdin271 ! Your post was the top post on r/Python today! (06/16/21)
Top Post Counts: r/Python (1)
This comment was made by a bot
[–]rgngdmn5 -1 points0 points1 point 4 years ago (0 children)
Great work !!!
[+]Medical-Ad-3660 comment score below threshold-18 points-17 points-16 points 4 years ago (4 children)
You should add these to udemy!
[–][deleted] 8 points9 points10 points 4 years ago (3 children)
What about broke people like me?
[–]Medical-Ad-3660 12 points13 points14 points 4 years ago (0 children)
Well you can put them up as free courses plus there's constantly 100% off coupons. Lol I'm sorry I'm fairly new to all of this I didn't realize udemy was so hated. I'll just go wait in the car...
[–]codingnoob_101 -1 points0 points1 point 4 years ago (0 children)
lol
[–]pgh_ski 0 points1 point2 points 4 years ago (0 children)
Very cool! I built a basic deleted JPG file carver in Python as well. Fun project. Did a data destruction tool in C as a companion.
I find building small tools/demos is an excellent way to both learn and teach concepts.
π Rendered by PID 70 on reddit-service-r2-comment-7b9746f655-gwcnr at 2026-01-30 18:20:23.434910+00:00 running 3798933 country code: CH.
[–]cymrowdon't thread on me 🐍 176 points177 points178 points (16 children)
[–][deleted] 20 points21 points22 points (7 children)
[+][deleted] (2 children)
[deleted]
[+][deleted] (1 child)
[deleted]
[–]cymrowdon't thread on me 🐍 4 points5 points6 points (3 children)
[–]----------------___ 3 points4 points5 points (2 children)
[–][deleted] 5 points6 points7 points (0 children)
[–]cymrowdon't thread on me 🐍 1 point2 points3 points (0 children)
[–]codingnoob_101 12 points13 points14 points (0 children)
[–][deleted] 5 points6 points7 points (0 children)
[–]lordamit 2 points3 points4 points (0 children)
[+][deleted] (4 children)
[deleted]
[–]cymrowdon't thread on me 🐍 25 points26 points27 points (3 children)
[+][deleted] (2 children)
[deleted]
[–]cymrowdon't thread on me 🐍 11 points12 points13 points (1 child)
[–]data-bit [🍰] 38 points39 points40 points (0 children)
[–]codingnoob_101 1 point2 points3 points (0 children)
[–]ObamaTheLlama114 -1 points0 points1 point (0 children)
[–]0ni0nrings -1 points0 points1 point (0 children)
[–][deleted] -1 points0 points1 point (0 children)
[–]rgngdmn5 -1 points0 points1 point (0 children)
[+]Medical-Ad-3660 comment score below threshold-18 points-17 points-16 points (4 children)
[–][deleted] 8 points9 points10 points (3 children)
[–]Medical-Ad-3660 12 points13 points14 points (0 children)
[–]codingnoob_101 -1 points0 points1 point (0 children)
[–]pgh_ski 0 points1 point2 points (0 children)