Last active
June 20, 2022 08:13
-
-
Save tkjaer/1779b0e5487d3d576327041e1804c40c to your computer and use it in GitHub Desktop.
Easily lookup IPs in the Shodan InternetDB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# Lookup IP (or IPs of hostname) in internetdb.shodan.io. | |
# Check if we have jq to print format nicely: | |
if which jq > /dev/null; then | |
_jq=jq | |
elif which gojq > /dev/null; then | |
_jq=gojq | |
else | |
echo "Please install 'jq' or 'gojq' before proceeding." | |
exit 1 | |
fi | |
function lookup { | |
echo "> Result for $1 in Shodan Internet DB:" | |
curl -s "https://internetdb.shodan.io/$1"|$_jq | |
echo "> See more information: https://www.shodan.io/host/$1" | |
} | |
# Print usage if we don't have any arguments: | |
if [ ! -z $1 ]; then | |
for arg in "$@" | |
do | |
# Check if IP matches IPv4 or IPv6 address. If not, look up host | |
# information and iterate over addresses to print results. | |
echo $arg|grep -E '^[0-9.:\/]+$' > /dev/null 2>&1 | |
if [ $? -eq 0 ]; then | |
hosts=( $(python3 -c "from ipaddress import ip_network; print('\n'.join([ str(ip) for ip in list(ip_network('"$arg"').hosts())]))")) | |
echo "${arg} contains ${#hosts[@]} hosts." | |
echo "Continue lookup? [YES/no]" | |
read CONTINUE | |
if [ "${CONTINUE}" != "no" ]; then | |
for host in ${hosts[@]};do | |
lookup ${host} | |
done | |
fi | |
exit | |
fi | |
echo $arg|grep -E '^[0-9.:]+$' > /dev/null 2>&1 | |
if [ $? -eq 0 ]; then | |
lookup $arg | |
else | |
echo "> Looking up $arg .." | |
hosts=( $(host ${arg}|awk '/address/ { print $NF }') ) | |
for host in "${hosts[@]}" | |
do | |
lookup ${host} | |
done | |
fi | |
done | |
else | |
echo "Usage examples:" | |
echo " $ shodan 1.1.1.1" | |
echo " $ shodan example.com" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment