r/learnpython • • Dec 23 '19

What are some creative small programs that you have coded using Python?

I am a beginner at coding with Python, so I am curious about learning what small programs or projects you all have created. I am hoping to develop my skills using Python, so I figured looking at actual code for various programs would greatly help.

Please include a short description of what the program does and the code itself in the comments below. Thank you!

348 Upvotes

224 comments sorted by

View all comments

63

u/Skippbo Dec 23 '19

When I put up a web server on my raspberry pi I once took a look at Apaches log file for incoming requests. It scared me with how much random traffic I was getting so i made this to add suspicious ips to my firewall.

It goes thru the log file for new ips and the database for old banned ips (30 days) and checks them against abuseIPDBs database and adds them to firewall if it's shady enough.

Main code is 200 lines with comments.

8

u/[deleted] Dec 23 '19

That's good cyber security practice. Really cool.

2

u/Skippbo Dec 23 '19

Thank you =D

-11

u/tejonaco Dec 23 '19 edited Dec 23 '19

Adding some feedback:

In the service file appears autorun_blacklister.py but the script name is autorun_ip_blacklister.py

Do you think that a racist filter (mainly block China attempts) will be useful?

EDIT: Just a little joke, most of malicious ip's come from China, in practice all ips coming out of your country into a private server should be blocked.

Looking at the log file I realised that Gecko and AppleWebKit are strongly used by our chinese botnet friends, it's possible to block webdrivers?

Thanks for you job!

7

u/Skippbo Dec 23 '19

about the service file, yes that is a mistake it is supposed to be autorun_ip_blacklister.py not autorun_blacklister.py eitherway its supposed to be changed to whatever is right for the users system.

About usefullness, Gecko and AppleWebKit. When I made this I simply googled around till I found something that I could use. I came across AbuseIPDB so thats what I used. i currently have 1200 IPs in my database so its at least doing something for me. If their database is considered racist I had no idea about that. Gecko and AppleWebKit is something I have not heard about so i wouldnt be able to tell sadly.

4

u/tejonaco Dec 23 '19

Maybe I try to do a fork of your project with the webdriver blocking, if it works I will send you in order of a possible merge

1

u/Skippbo Dec 23 '19

That would be welcome!

2

u/Skippbo Dec 23 '19

I looked through the log file once again and see what you mean. Using my method it would be possible but without a refined algoritm it would probably catch alot of false positives. This is why I looked for external sources for evaluating the shady requests as I do not have the knowledge myself to do so. After googling I found AbuseIPDB and thats why I used that.

2

u/[deleted] Dec 23 '19

A racist python script?

1

u/JS_int_type Dec 23 '19

racist filter

Injecting IDPOL into a discussion regarding bad actors is pretty dumb. The goal is to block bad actors, not navelgaze.

2

u/[deleted] Dec 23 '19

Lol wtf

1

u/tejonaco Dec 23 '19

It was a little joke since all malicious ips that I registered come from China, a private server could block all ips coming from there because it will be malicious.