-
Notifications
You must be signed in to change notification settings - Fork 337
/
ipgeolocation.py
98 lines (72 loc) · 3.44 KB
/
ipgeolocation.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
#!/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'
import sys, os
from core.IpGeoLocationLib import IpGeoLocationLib
from core.Logger import Logger
from core.Menu import parser,args,banner
def main():
# no args provided
if len(sys.argv) == 1:
parser.print_help()
sys.exit(1)
logsDir = os.path.join(os.getcwd(), 'logs')
#resultsDir = os.path.join(os.getcwd(), 'results')
if not os.path.exists(logsDir):
os.mkdir(logsDir)
#if not os.path.exists(resultsDir):
# os.mkdir(resultsDir)
logger = Logger(args.nolog, args.verbose)
#single target or multiple targets
if(args.target and args.tlist):
logger.PrintError("You can request Geolocation information either for a single target(-t) or a list of targets(-T). Not both!", args.nolog)
sys.exit(2)
#my ip address or single target
if(args.target and args.myip):
logger.PrintError("You can request Geolocation information either for a single target(-t) or your own IP address. Not both!", args.nolog)
sys.exit(3)
#multiple targets or my ip address
if(args.tlist and args.myip):
logger.PrintError("You can request Geolocation information either for a list of targets(-T) or your own IP address. Not both!", args.nolog)
sys.exit(4)
#single target and google maps only allowed
if(args.tlist and args.g):
logger.PrintError("Google maps location is working only with single targets.", args.nolog)
sys.exit(5)
#specify user-agent or random
if(args.uagent and args.ulist):
logger.PrintError("You can either specify a user-agent string or let IPGeolocation pick random user-agent strings for you from a file.", args.nolog)
sys.exit(6)
#specify proxy or random
if(args.proxy and args.xlist):
logger.PrintError("You can either specify a proxy or let IPGeolocation pick random proxy connections for you from a file.", args.nolog)
sys.exit(7)
#init lib
ipGeoLocRequest = IpGeoLocationLib(args.target, logger, args.noprint)
print(banner)
#retrieve information
if not ipGeoLocRequest.GetInfo(args.uagent, args.tlist,
args.ulist, args.proxy, args.xlist,
args.csv, args.xml, args.txt, args.g):
logger.PrintError("Retrieving IP Geolocation information failed.")
sys.exit(8)
if __name__ == '__main__':
main()