-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstaller.py
More file actions
212 lines (170 loc) · 6.71 KB
/
installer.py
File metadata and controls
212 lines (170 loc) · 6.71 KB
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
#!/usr/bin/env python3
"""
Installer for IPFinder Command
"""
import os
import sys
import platform
import shutil
def check_dependencies():
"""Check for required packages"""
required_packages = []
missing = []
for package in required_packages:
try:
__import__(package.replace('-', '_'))
print(f"✓ {package} is installed")
except ImportError:
missing.append(package)
if missing:
print("\nMissing dependencies:")
for package in missing:
print(f" ✗ {package}")
print(f"\nInstall with: {sys.executable} -m pip install {' '.join(missing)}")
return False
print("✓ All dependencies are satisfied (standard library only)")
return True
def get_install_dir():
"""Get appropriate installation directory"""
system = platform.system()
if system == "Windows":
python_dir = os.path.dirname(sys.executable)
scripts_dir = os.path.join(python_dir, "Scripts")
if os.path.exists(scripts_dir):
return scripts_dir
home = os.path.expanduser("~")
user_bin = os.path.join(home, "bin")
os.makedirs(user_bin, exist_ok=True)
return user_bin
else:
if os.geteuid() == 0:
return "/usr/local/bin"
if os.access("/usr/local/bin", os.W_OK):
return "/usr/local/bin"
home = os.path.expanduser("~")
local_bin = os.path.join(home, ".local", "bin")
os.makedirs(local_bin, exist_ok=True)
return local_bin
def check_in_path(directory):
"""Check if directory is in PATH"""
path_env = os.environ.get("PATH", "")
path_dirs = path_env.split(os.pathsep)
return directory in path_dirs
def create_wrapper(install_dir, script_path):
"""Create platform-specific wrapper"""
system = platform.system()
if system == "Windows":
wrapper = os.path.join(install_dir, "ipfinder.bat")
content = f'''@echo off
"{sys.executable}" "{script_path}" %*
'''
with open(wrapper, "w", encoding="utf-8") as f:
f.write(content)
return wrapper
else:
wrapper = os.path.join(install_dir, "ipfinder")
content = f'''#!/bin/sh
"{sys.executable}" "{script_path}" "$@"
'''
with open(wrapper, "w", encoding="utf-8") as f:
f.write(content)
os.chmod(wrapper, 0o755)
return wrapper
def add_to_path(install_dir):
"""Instructions for adding directory to PATH"""
system = platform.system()
print(f"\n⚠️ {install_dir} is not in your PATH")
if system == "Windows":
print(f"\nTo add to PATH permanently:")
print(f"1. Press Win + X, select 'System'")
print(f"2. Click 'Advanced system settings'")
print(f"3. Click 'Environment Variables'")
print(f"4. Under 'User variables', select 'Path'")
print(f"5. Click 'Edit' and add: {install_dir}")
print(f"6. Restart your terminal")
elif system == "Darwin":
shell = os.environ.get("SHELL", "").split("/")[-1]
rc_file = "~/.zshrc" if shell == "zsh" else "~/.bash_profile"
print(f"\nAdd to {rc_file}:")
print(f' echo \'export PATH="{install_dir}:$PATH"\' >> {rc_file}')
print(f" source {rc_file}")
else:
shell = os.environ.get("SHELL", "").split("/")[-1]
rc_file = "~/.bashrc" if shell == "bash" else "~/.zshrc"
print(f"\nAdd to {rc_file}:")
print(f' echo \'export PATH="{install_dir}:$PATH"\' >> {rc_file}')
print(f" source {rc_file}")
def main():
print(f"""{'='*50}
IPFinder - Passive IP Intelligence and Reconnaissance Tool
{'='*50}""")
print("Features:")
print(" ✓ Passive analysis only (no active scanning)")
print(" ✓ Cross-platform compatibility")
print(" ✓ Geolocation with full country names")
print(" ✓ Decimal IP conversion")
print(" ✓ Reverse DNS lookup")
print(" ✓ Animated loading indicator")
print(" ✓ Clean color-coded output")
print(f"{'='*50}")
if sys.version_info < (3, 6):
print("Error: Python 3.6+ required")
sys.exit(1)
print("\n🔍 Checking dependencies...")
if not check_dependencies():
print("\nPlease install dependencies first")
response = input("Continue anyway? [Y/n]: ").strip().lower()
if response not in ('', 'y', 'yes'):
sys.exit(1)
script_dir = os.path.dirname(os.path.abspath(__file__))
main_script = os.path.join(script_dir, "ipfinder.py")
if not os.path.exists(main_script):
print(f"Error: ipfinder.py not found in {script_dir}")
sys.exit(1)
install_dir = get_install_dir()
print(f"\n📁 Installation directory: {install_dir}")
os.makedirs(install_dir, exist_ok=True)
dest_script = os.path.join(install_dir, "ipfinder.py")
try:
shutil.copy2(main_script, dest_script)
print(f"✓ Script copied to {dest_script}")
except PermissionError:
print(f"\nPermission denied: {install_dir}")
print("Try: sudo python installer.py")
sys.exit(1)
wrapper = create_wrapper(install_dir, dest_script)
print(f"✓ Wrapper created: {wrapper}")
if check_in_path(install_dir):
print(f"\n{'✅'*5} Installation Complete! {'✅'*5}")
print(f"\n📖 Usage examples:")
print(f" ipfinder # Interactive mode")
print(f" ipfinder 8.8.8.8 # Analyze specific IP")
print(f" ipfinder -i # Get your public IP")
print(f" ipfinder -n # No colors")
print(f" ipfinder -h # Help")
print(f"\n🛡️ Security features:")
print(f" • Passive analysis only")
print(f" • No port scanning")
print(f" • No packet crafting")
print(f" • No active probing")
print(f"\n🌍 Sources:")
print(f" • ipinfo.io for geolocation")
print(f" • System reverse DNS")
print(f" • Multiple public IP services")
else:
add_to_path(install_dir)
print(f"\n{'✅'*5} Installation Complete! {'✅'*5}")
print(f"\nAfter adding to PATH, use:")
print(f" ipfinder [options] [ip_address]")
print(f"\n{'='*50}")
print("⚠️ IMPORTANT: Use responsibly!")
print(" This tool is for educational and legitimate")
print(" reconnaissance purposes only.")
print(" Always respect privacy and applicable laws.")
return 0
if __name__ == "__main__":
try:
sys.exit(main())
except KeyboardInterrupt:
print("\n\nInstallation cancelled")
sys.exit(1)