Created
January 10, 2020 15:48
-
-
Save xyzkab/1f7af15ba8bfc412832048b64ee15186 to your computer and use it in GitHub Desktop.
Extract domains from ip address using nmap ssl-cert script
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
#!/bin/bash | |
target_ip=$1 | |
[[ -z "$target_ip" ]] && echo "We need target ip" && exit 1 | |
results=$(nmap -p 443 --script ssl-cert $target_ip | grep -oP '(?<=Subject: |Name: ).*') | |
domains=$(for name in `echo $results`; do | |
name=$(echo $name | sed -E 's/:|=/ /g' | awk '{print $NF}') # replace (:) or (=) to space and get last element($NF) | |
name=$(echo $name | sed -E 's/\*\.|\,//g') # remove .*(wildcard) and last comma(,) | |
name=$(echo $name | sed 's/\r$//g') # cleanup carriage return(CR) | |
echo $name | |
done) | |
echo "$domains" | sort -u |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment