Skip to content

Instantly share code, notes, and snippets.

@xyzkab
Created January 10, 2020 15:48
Show Gist options
  • Save xyzkab/1f7af15ba8bfc412832048b64ee15186 to your computer and use it in GitHub Desktop.
Save xyzkab/1f7af15ba8bfc412832048b64ee15186 to your computer and use it in GitHub Desktop.
Extract domains from ip address using nmap ssl-cert script
#!/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