-
Notifications
You must be signed in to change notification settings - Fork 79
Expand file tree
/
Copy pathalienvault.sh
More file actions
56 lines (42 loc) · 1.35 KB
/
alienvault.sh
File metadata and controls
56 lines (42 loc) · 1.35 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
#!/bin/bash
# Check if jq is installed.
if ! command -v jq &>/dev/null; then
echo "jq is required but not installed. Please install jq and rerun this script."
exit 1
fi
# Check if domain is provided as an argument.
if [ -z "$1" ]; then
echo "Usage: $0 <domain>"
exit 1
fi
# Get domain from argument.
domain=$1
# Set initial pagination parameters.
page=1
limit=500
echo "Fetching URLs from AlienVault OTX for domain: $domain"
while true; do
echo "Fetching page $page..."
# Retrieve the JSON response for the current page.
response=$(curl -s "https://otx.alienvault.com/api/v1/indicators/hostname/${domain}/url_list?limit=${limit}&page=${page}")
# Extract URLs from the JSON response.
urls=$(echo "$response" | jq -r '.url_list[]?.url')
# If no URLs were returned, break the loop.
if [[ -z "$urls" ]]; then
echo "No more URLs found on page $page. Finishing."
break
fi
# Print the retrieved URLs.
echo "$urls"
# Count how many URLs were returned on this page.
count=$(echo "$response" | jq -r '.url_list | length')
echo "Found $count URL(s) on page $page."
# If fewer URLs than the limit were returned, assume it's the last page.
if (( count < limit )); then
echo "Reached the last page."
break
fi
# Increment page number for the next iteration.
page=$((page + 1))
done
echo "Done fetching URLs."