Created
November 16, 2021 02:49
-
-
Save dhruvilp/3471c2f84cfa5200570419b04cb087ec to your computer and use it in GitHub Desktop.
CTF: Ping & get DNS name from a list of IPs saved in a file
This file contains hidden or 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/zsh | |
| #Ping & get DNS name from a list of IPs saved in a file | |
| #Prompt the user to enter a file name and its path. | |
| read -p "Enter the IP addresses file name / path:" FILE_PATH_NAME | |
| function check_host(){ | |
| #if not the IP address value is empty | |
| if [[ -n $IP_ADDRESS ]] | |
| then | |
| ping_cmd=$(nmap -sn $IP_ADDRESS| grep 'Host is up' | cut -d '(' -f 1) | |
| echo '------------------------------------------------' | |
| if [[ -z $ping_cmd ]] | |
| then | |
| printf "$IP_ADDRESS is down\n" | |
| else | |
| printf "$IP_ADDRESS is up\n" | |
| dns_name | |
| fi | |
| fi | |
| } | |
| function dns_name(){ | |
| dns_name=$(host $IP_ADDRESS) | |
| printf "$dns_name\n" | |
| } | |
| #Iterate through the IP addresses inside the file | |
| for ip in $(cat $FILE_PATH_NAME) | |
| do | |
| IP_ADDRESS=$ip | |
| check_host | |
| done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment