forked from maldevel/IPGeoLocation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMenu.py
154 lines (113 loc) · 5.41 KB
/
Menu.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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#!/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'
__twitter__ = '@maldevel'
__version__ = '2.0.4'
__year__ = '2015-2016'
from argparse import RawTextHelpFormatter
import argparse, os
from urllib.parse import urlparse
from core.Logger import Red
banner = """
{0}
{1} Retrieve IP Geolocation information from ip-api.com
{1} Copyright (c) {2} {3} ({4})
{1} ip-api.com service will automatically ban any IP addresses doing over 150 requests per minute.
""".format(Red('IPGeolocation ' + __version__), Red('--['), __year__, __author__, __twitter__)
def checkFileRead(filename):
"""Check if file exists and we have access to read it"""
if os.path.isfile(filename) and os.access(filename, os.R_OK):
return filename
else:
raise argparse.ArgumentTypeError("Invalid {} file (File does not exist, insufficient permissions or it's not a file).".format(filename))
def checkFileWrite(filename):
"""Check if we can write to file"""
if os.path.isfile(filename):
raise argparse.ArgumentTypeError("File {} already exists.".format(filename))
elif os.path.isdir(filename):
raise argparse.ArgumentTypeError("Folder provided. Please provide a file.")
elif os.access(os.path.dirname(filename), os.W_OK):
return filename
else:
raise argparse.ArgumentTypeError("Unable to write to {} file (Insufficient permissions).".format(filename))
def checkProxyUrl(url):
"""Check if proxy url is valid"""
url_checked = urlparse(url)
if (url_checked.scheme not in ('http', 'https')) | (url_checked.netloc == ''):
raise argparse.ArgumentTypeError('Invalid {} Proxy URL (example: http://127.0.0.1:8080).'.format(url))
return url_checked
parser = argparse.ArgumentParser(description=banner, formatter_class=RawTextHelpFormatter)
#pick target/s
parser.add_argument('-m', '--my-ip',
dest='myip',
action='store_true',
help='Get Geolocation info for my IP address.')
parser.add_argument('-t', '--target',
help='IP Address or Domain to be analyzed.')
parser.add_argument('-T', '--tlist',
metavar='file',
type=checkFileRead,
help='A list of IPs/Domains targets, each target in new line.')
#user-agent configuration
parser.add_argument('-u', '--user-agent',
metavar='User-Agent',
dest='uagent',
default='IP2GeoLocation {}'.format(__version__),
help='Set the User-Agent request header (default: IP2GeoLocation {}).'.format(__version__))
parser.add_argument('-U', '--ulist',
metavar='file',
type=checkFileRead,
help='A list of User-Agent strings, each string in new line.')
#misc options
parser.add_argument('-g',
action='store_true',
help='Open IP location in Google maps with default browser.')
parser.add_argument('--noprint',
action='store_true',
help='IPGeolocation will print IP Geolocation info to terminal. It is possible to tell IPGeolocation not to print results to terminal with this option.')
parser.add_argument('-v', '--verbose',
action='store_true',
help='Enable verbose output.')
parser.add_argument('--nolog',
action='store_true',
help='IPGeolocation will save a .log file. It is possible to tell IPGeolocation not to save those log files with this option.')
#anonymity options
parser.add_argument('-x', '--proxy',
type=checkProxyUrl,
help='Setup proxy server (example: http://127.0.0.1:8080)')
parser.add_argument('-X', '--xlist',
metavar='file',
type=checkFileRead,
help='A list of proxies, each proxy url in new line.')
#export options
parser.add_argument('-e', '--txt',
metavar='file',
type=checkFileWrite,
help='Export results.')
parser.add_argument('-ec', '--csv',
metavar='file',
type=checkFileWrite,
help='Export results in CSV format.')
parser.add_argument('-ex', '--xml',
metavar='file',
type=checkFileWrite,
help='Export results in XML format.')
args = parser.parse_args()