-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtracehawk.py
More file actions
76 lines (65 loc) · 2.33 KB
/
Copy pathtracehawk.py
File metadata and controls
76 lines (65 loc) · 2.33 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
import os
import http.server
import socketserver
import threading
import requests
from urllib.parse import urlparse
from time import sleep
# Define the HTTP request handler
class IPLoggerHandler(http.server.SimpleHTTPRequestHandler):
def do_GET(self):
# Get real IP from X-Forwarded-For header (set by Ngrok)
forwarded_ip = self.headers.get('X-Forwarded-For')
if forwarded_ip:
visitor_ip = forwarded_ip.split(',')[0].strip()
else:
visitor_ip = self.client_address[0]
print(f"\n[+] Visitor IP: {visitor_ip}")
try:
# Query IP geolocation
res = requests.get(f"http://ip-api.com/json/{visitor_ip}").json()
print(res)
except Exception as e:
print(f"[!] Failed to get IP info: {e}")
# Respond to visitor
self.send_response(200)
self.send_header('Content-type', 'text/html')
self.end_headers()
self.wfile.write(b"<h1>Thanks! Your IP has been logged.</h1>")
def start_server():
with socketserver.TCPServer(("localhost", 8000), IPLoggerHandler) as httpd:
print("[+] Server running on http://localhost:8000")
httpd.serve_forever()
def start_ngrok(authtoken):
os.system("pkill ngrok")
os.system(f"ngrok config add-authtoken {authtoken}")
os.system("ngrok http 8000 > /dev/null &")
sleep(2)
try:
tunnel_info = requests.get("http://127.0.0.1:4040/api/tunnels").json()
public_url = tunnel_info["tunnels"][0]["public_url"]
print(f"[+] Share this link: {public_url}")
except Exception as e:
print(f"[!] Ngrok failed: {e}")
def main():
print("=== Python IP Logger with Ngrok ===")
authtoken = input("[?] Enter your Ngrok authtoken: ").strip()
if not authtoken:
print("[!] Authtoken is required. Exiting.")
return
choice = input("[?] Generate tracking link? (Y/N): ").strip().lower()
if choice != 'y':
print("[!] Exiting.")
return
start_ngrok(authtoken)
try:
server_thread = threading.Thread(target=start_server)
server_thread.daemon = True
server_thread.start()
print("[!] Press CTRL+C to stop...")
while True:
sleep(1)
except KeyboardInterrupt:
print("\n[!] Server stopped.")
if __name__ == "__main__":
main()