-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathresolve.py
More file actions
40 lines (33 loc) · 1.08 KB
/
Copy pathresolve.py
File metadata and controls
40 lines (33 loc) · 1.08 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
import pandas as pd
import requests
# Load the CSV file
df = pd.read_csv('./trimmed_data.csv')
# Select all unique source IP addresses
unique_ips = df['dst.ip'].unique()
# Function to resolve IP address using ipinfo.io
def resolve_ip(ip):
response = requests.get(f'https://ipinfo.io/{ip}/json?token=XXX')
if response.status_code == 200:
data = response.json()
return {
'dst.ip': ip,
'hostname': data.get('hostname', ''),
'city': data.get('city', ''),
'country': data.get('country', ''),
'org': data.get('org', '')
}
else:
return {
'dst.ip': ip,
'hostname': '',
'city': '',
'country': '',
'org': ''
}
# Resolve all unique IP addresses
resolved_ips = [resolve_ip(ip) for ip in unique_ips]
# Create a DataFrame from the resolved IP information
resolved_df = pd.DataFrame(resolved_ips)
# Save the DataFrame to a CSV file
resolved_df.to_csv('ipresolve.csv', index=False)
print("IP resolution information has been saved to ipresolve.csv")