[stickynotes-antispam] Delete paste if contains more than 2 IP addresse



commit e405e34224b2b050299754749011cbcb730893b4
Author: Bartłomiej Piotrowski <bpiotrowski gnome org>
Date:   Sun Apr 5 20:00:10 2020 +0200

    Delete paste if contains more than 2 IP addresse

 stickynotes-antispam.py | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
---
diff --git a/stickynotes-antispam.py b/stickynotes-antispam.py
index 1383fc6..5406acf 100755
--- a/stickynotes-antispam.py
+++ b/stickynotes-antispam.py
@@ -1,5 +1,6 @@
 #!/usr/bin/python3
 
+import ipaddress
 import os
 import re
 import sys
@@ -8,6 +9,8 @@ import MySQLdb
 
 BLACKLIST = [
     "bitcoin",
+    "drugs",
+    "hacking",
     "loan",
     "movie",
     "paypal",
@@ -36,6 +39,18 @@ def check_if_spam(data):
     if link_count >= 2:
         return True
 
+    # Delete paste if contains more than 2 IP addresses
+    ip_count = 0
+    for line in lines:
+        try:
+            if ipaddress.ip_address(line.split(":")[0]):
+                ip_count += 1
+        except ValueError:
+            pass
+
+    if ip_count >= 2:
+        return True
+
     # Spammers tend to paste the same URL n times
     firstline = lines[0]
     repeat_counter = lines.count(firstline)


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]