-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfinding_IP.py
More file actions
47 lines (35 loc) · 1.42 KB
/
finding_IP.py
File metadata and controls
47 lines (35 loc) · 1.42 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
import json
from collections import defaultdict
# Path to your JSON file
json_file_path = "ip_logs.json"
# Dictionary to store unique IP-endpoint combinations
ip_endpoint_map = defaultdict(set)
# Dictionary to store counts of /api/ accesses per IP
api_access_count = defaultdict(int)
# Load and process the JSON data
with open(json_file_path, 'r') as file:
logs = json.load(file)
# Extract unique IP and endpoint combinations
for entry in logs:
ip = entry.get("ip_address")
endpoint = entry.get("endpoint")
time = entry.get('timestamp')
if ip and endpoint:
ip_endpoint_map[ip].add(endpoint)
# Count /api/ accesses specifically
if endpoint == "/api/":
api_access_count[ip] += 1
# Output the results
print(f"Found {len(ip_endpoint_map)} unique IP addresses:")
print("-" * 50)
for ip, endpoints in ip_endpoint_map.items():
print(f"IP: {ip}")
print(f"Accessed endpoints: {', '.join(endpoints)}")
# Show API access count if there were any
if api_access_count[ip] > 0:
print(f"API endpoint access count: {api_access_count[ip]}")
print("-" * 50)
# Summary of API access
total_api_calls = sum(api_access_count.values())
print(f"\nTotal /api/ endpoint calls: {total_api_calls}")
print(f"IPs accessing /api/ endpoint: {len(api_access_count)}")