forked from maldevel/IPGeoLocation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLogger.py
102 lines (74 loc) · 3.5 KB
/
Logger.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#!/usr/bin/env python3
# encoding: UTF-8
"""
This file is part of IPGeoLocation tool.
Copyright (C) 2015-2016 @maldevel
https://github.com/maldevel/IPGeoLocation
IPGeoLocation - Retrieve IP Geolocation information
Powered by http://ip-api.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
For more see the file 'LICENSE' for copying permission.
"""
__author__ = 'maldevel'
from datetime import datetime
import os
from termcolor import colored
from sys import platform as _platform
if _platform == 'win32':
import colorama
colorama.init()
def Red(value):
return colored(value, 'red', attrs=['bold'])
def Green(value):
return colored(value, 'green', attrs=['bold'])
class Logger:
def __init__(self, nolog=False, verbose=False):
self.NoLog = nolog
self.Verbose = verbose
def WriteLog(self, messagetype, message):
filename = '{}.log'.format(datetime.strftime(datetime.now(), "%Y%m%d"))
path = os.path.join('.', 'logs', filename)
with open(path, 'a') as logFile:
logFile.write('[{}] {} - {}\n'.format(messagetype, datetime.strftime(datetime.now(), "%Y-%m-%d %H:%M:%S"), message))
def PrintError(self, message):
"""Print/Log error message"""
if not self.NoLog:
self.WriteLog('ERROR', message)
print('[{}] {}'.format(Red('ERROR'), message))
def PrintResult(self, title, value):
"""print result to terminal"""
print('{}: {}'.format(title, Green(value)))
def Print(self, message):
"""print/log info message"""
if not self.NoLog:
self.WriteLog('INFO', message)
if self.Verbose:
print('[{}] {}'.format(Green('**'), message))
def PrintIPGeoLocation(self, ipGeoLocation):
"""print IP Geolocation information to terminal"""
self.PrintResult('\nTarget', ipGeoLocation.Query)
self.PrintResult('IP', ipGeoLocation.IP)
self.PrintResult('ASN', ipGeoLocation.ASN)
self.PrintResult('City', ipGeoLocation.City)
self.PrintResult('Country', ipGeoLocation.Country)
self.PrintResult('Country Code', ipGeoLocation.CountryCode)
self.PrintResult('ISP', ipGeoLocation.ISP)
self.PrintResult('Latitude', str(ipGeoLocation.Latitude))
self.PrintResult('Longtitude', str(ipGeoLocation.Longtitude))
self.PrintResult('Organization', ipGeoLocation.Organization)
self.PrintResult('Region Code', ipGeoLocation.Region)
self.PrintResult('Region Name', ipGeoLocation.RegionName)
self.PrintResult('Timezone', ipGeoLocation.Timezone)
self.PrintResult('Zip Code', ipGeoLocation.Zip)
self.PrintResult('Google Maps', ipGeoLocation.GoogleMapsLink)
print()
#.encode('cp737', errors='replace').decode('cp737')