Skip to content

Instantly share code, notes, and snippets.

@Ali-Razmjoo
Created June 4, 2017 17:30
Show Gist options
  • Save Ali-Razmjoo/6b3f3174c5aab08c6d27a3af07e9ff1c to your computer and use it in GitHub Desktop.
Save Ali-Razmjoo/6b3f3174c5aab08c6d27a3af07e9ff1c to your computer and use it in GitHub Desktop.
#!/usr/bin/python
import os
import time
while 1:
time.sleep(0.2)
result = os.popen('netstat -tuna | grep :80 | grep SYN_RECV').read().rsplit('\n')
try:
flag = False
for ip in result:
if len(ip) is 6:
flag = True
text_word = ip[5].rsplit(':')[0]
print 'banned',text_word
deny = 'iptables -I INPUT -s %s -j DROP' %text_word # it use iptables to ban users
os.system(deny)
deny = 'iptables -A INPUT -s %s -j DROP' %text_word
os.system(deny)
ipsave = open('/root/Banned.txt','a') #save ip banned for me
ip_add = text_word + '\n'
ipsave.write(ip_add)
ipsave.close()
if flag is True:
os.system('service iptables-persistent save')
os.system('service iptables-persistent restart')
except:
print 'error'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment