import socket
from geoip import geolite2


class BearStorage():
    def __init__(self, ip, rawrequest, timestamp, parsed_request, isDetected,
                 hostname):
        self.ip = ip  # String
        self.rawrequest = rawrequest  # String
        self.timestamp = timestamp  # Datetime
        self.path = parsed_request.path  # String
        self.command = parsed_request.command  # String
        self.version = parsed_request.request_version  # String
        self.headers = parsed_request.headers  # Dictionary
        self.isDetected = isDetected  # Bool
        self.hostname = hostname  # Bool
        location = geolite2.lookup(ip)
        if location is not None:
            self.country = location.country  # String
            self.continent = location.continent  # String
            self.timezone = location.timezone  # String
        else:
            self.country = ''
            self.continent = ''
            self.timezone = ''
        self.tracert = ""  # TODO
        try:
            self.dnsname = socket.gethostbyaddr(ip)[0]  # String
        except:
            self.dnsname = ""

    def __str__(self):
        output = "hostname: " + self.hostname + "\r\n"
        output += "IP: " + self.ip + "\r\n"
        # output += "rawrequest: " + self.rawrequest + "\r\n"
        output += "timestamp: " + self.timestamp + "\r\n"
        output += "path: " + self.path + "\r\n"
        output += "command: " + self.command + "\r\n"
        output += "version: " + self.version + "\r\n"
        # output += "headers: " + str(self.headers) + "\r\n"
        output += "country: " + self.country + "\r\n"
        output += "continent: " + self.continent + "\r\n"
        output += "timezone: " + self.timezone + "\r\n"
        if self.isDetected:
            output += "Detected: Yes" + "\r\n"
        else:
            output += "Detected: No" + "\r\n"
        return output

    def __repr__(self):
        return self.__str__()

# import subprocess
# host = 'www.microsoft.com'
# p = subprocess.Popen(["tracert", '-d', '-w', '100', host],
#                      stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
# while True:
#     line = p.stdout.readline()
#     if not line:
#         break
#     print '-->', line,
# p.wait()

@@ -518,16 +518,143 @@
 tionary%0A
+        try:%0A            self.ua = parsed_request.headers%5B'User-Agent'%5D  # Dictionary%0A        except:%0A            self.ua = %22%22%0A
         
@@ -1471,32 +1471,84 @@
 estamp + %22%5Cr%5Cn%22%0A
+        output += %22User-Agent: %22 + self.ua + %22%5Cr%5Cn%22%0A
         output +

Add useragent to bearstorage