Skip to content

Instantly share code, notes, and snippets.

@h0bbel
Last active November 1, 2023 12:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save h0bbel/7aaea28c3b98ff925bbaf22ff7b0b718 to your computer and use it in GitHub Desktop.
Save h0bbel/7aaea28c3b98ff925bbaf22ff7b0b718 to your computer and use it in GitHub Desktop.
# Script to update a given Shodan Alert with new public IP, if the IP has changed
# v0.5 — Christian Mohn | vNinja.net
#!/bin/bash
# Variables
MYIPFILE="shodanip.txt" # The file where you keep your current public IP
MYIP=`shodan myip` # Get public IP through Shodan CLI and store it in the $MYIP variable
SHODANALERTID="XXXXXXXXXXXXXXXX" # Shodan Alert ID — NB! Replace with your own
SHODANAPIKEY="XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" # Shodan API Key — NB! Replace with your own
if test -f "$MYIPFILE"; then
# $MYIPFILE exists
read -r STOREDIP<$MYIPFILE # Read first line of $MYIPFILE and store it in #STOREDIP
if [ $MYIP = $STOREDIP ]
then
echo "Public IP matches current value $MYIP. \nShodan AlertID: $SHODANALERTID not updated."
else
echo "Public IP does not match IP in file.\nUpdating Shodan AlertID: $SHODANALERTID."
echo "$MYIP" > $MYIPFILE
# Run CURL to update Shodan REST API
curl -X POST "https://api.shodan.io/shodan/alert/$SHODANALERTID?key=$SHODANAPIKEY" --silent -H 'Content-Type: application/json' -d'
{
"filters": {
"ip": [
"'$MYIP'"
]
}
}
' > /dev/null
fi
else
# File does not exist
echo "$MYIPFILE does not exist. Creating file."
echo "$MYIP" > $MYIPFILE
echo "Current public IP: $MYIP"
echo "$MYIP" > $MYIPFILE
echo "Updating Shodan AlertID: $SHODANALERTID."
# Run CURL to update Shodan REST API
curl -X POST "https://api.shodan.io/shodan/alert/$SHODANALERTID?key=$SHODANAPIKEY" --silent -H 'Content-Type: application/json' -d'
{
"filters": {
"ip": [
"'$MYIP'"
]
}
}
' > /dev/null
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment