Created
November 22, 2015 17:54
-
-
Save Logic-gate/bc80e3c199725faa4c51 to your computer and use it in GitHub Desktop.
I needed a simple way to manually report suspicious actions on or to my server.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env python | |
import datetime | |
import urllib | |
import os | |
class REPORT(): | |
def cons(self): | |
date_now = datetime.datetime.now() | |
date = date_now.strftime("%Y_%m_%d") | |
time = date_now.strftime("%H:%M") | |
return date, time | |
def path(self): | |
path = '' #where do you want it to be saved | |
name = self.cons()[0] | |
name_path = str(path+name) | |
return name_path | |
def content(self, title, ip, source, affected_protocol, summary): | |
time = self.cons()[1] | |
format=""" | |
Time: """+time+""" | |
Title: """+title+""" | |
"""+source+""" | |
Proto: """+affected_protocol+""" | |
Summary: | |
"""+summary+"""\n----------------""" | |
return format | |
def get_location(self, ip): | |
response = urllib.urlopen('http://api.hostip.info/get_html.php?ip=%s&position=true' %ip) | |
location = response.read() | |
return location | |
def drop(self, ip): | |
os.system('iptables -A INPUT -s %s -j DROP' %ip) | |
print "%s Blocked" %ip | |
os.system('iptables -L INPUT -n -v') | |
return | |
if __name__ == '__main__': | |
title = raw_input('Title: ') | |
ip = raw_input('IP: ') | |
affected_protocol = raw_input('Proto: ') | |
summary = raw_input('Summary:\n') | |
def save(): | |
x = REPORT() | |
x.drop(ip) | |
content = x.content(title, ip, x.get_location(ip), affected_protocol, summary) | |
path = x.path() | |
x = open(path, 'a') | |
x.write(content) | |
print 'Saved...' | |
x.close() | |
save() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment