#!/bin/bash

set -xv
#main options
QUOTE="'"
DOUBLEQUOTE='"'
read -p 'Enter target domain: ' TARGET_DOMAIN
resolveip -s $TARGET_DOMAIN
read -p 'Enter target ip(ip for checking target response): ' TARGET_IP
read -p 'Enter CIDR (for zmap, format: x.x.x.x/x): ' CIDR
read -p 'Enter target port(80,443,8080,8443): ' TARGET_PORT
read -p 'Enter target url-path (/zmap/zmap.html): ' URL_PATH
ifconfig
read -p 'Enter interface (ifconfig): ' INTERFACE
read -p 'Enter rate : ' RATE
find_ip ()
{
        zmap -i $INTERFACE -p $TARGET_PORT $CIDR --rate=$RATE | sed s/$/,$TARGET_DOMAIN/ | zgrab -port $TARGET_PORT -http=$DOUBLEQUOTE$URL_PATH$DOUBLEQUOTE | grep -i $DOUBLEQUOTE$UNIQ_WORD$DOUBLEQUOTE | grep -oE '\b([0-9]{1,3}\.){3}[0-9]{1,3}\b' > /home/$TARGET_DOMAIN.txt



}

find_ip2 ()
{
        zmap -i $INTERFACE -p $TARGET_PORT $CIDR --rate=$RATE | zgrab -port $TARGET_PORT -tls | grep --color-always -i $DOUBLEQUOTE$UNIQ_WORD$DOUBLEQUOTE

}

check_ip ()
{
        curl -k -H "Host: $TARGET_DOMAIN" http://$TARGET_IP$URL_PATH
}

check_ip
      

while true; do
        read -p "Do you wish to continue?(Y,N) " yn
        case $yn in
                [Yy]* ) read -p 'Enter grep keyword: ' UNIQ_WORD;echo $UNIQ_WORD;find_ip2;echo "done"; break;;
                [Nn]* ) exit;;
                *) echo "Please answer yes or no.";;
        esac
done

set +xv

