Created
March 21, 2018 00:48
-
-
Save ericwastaken/e4134adaae123ef993dd16b70f16c271 to your computer and use it in GitHub Desktop.
Given the file path of a file has a hostname per line, looks up the IP for each host
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/sh | |
# ********************************************************************* | |
# script: filetoiplist | |
# summary: given a file path (assuming it has a host per line), looks | |
# up the IP for each host. | |
# dependencies: host; grep | |
# by: e.a.soto, [email protected] | |
# | |
# history | |
# ======= | |
# | |
# 2015-09-16: created. | |
# | |
# ********************************************************************* | |
if [ $# -eq 0 ] | |
then | |
echo "File Path must be supplied!" | |
exit 1 | |
fi | |
# basic logic | |
# | |
# use for to loop through each line in the file (which cat is reading) | |
# does "host" command in each file which returns info on the host, including IP | |
# pipes to grep looking for the line with "has address" which has the IPv4 address | |
# pipes to cut, splitting on spaces, 4th "field" will be the IP | |
# finally pipes to sort with -u (unique) for a unique ip list! | |
for url in $(cat "$1") | |
do host $url | |
done | | |
grep "has address" | | |
cut -d" " -f4 | | |
sort -u |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment