IP to Host

- ipconfig and scrape
- vi insert to a source file
- remove leading and trailing whitespaces
{quote}cat source | sed 's/^\[ \\\t\]*//' | sed 's/\[ \\\t\]*$//' > list{quote}
- cut out the subnet and gateway lines
{quote}cat list | sed s/^Sub.*// | sed s/^Defa.*// > new_list{quote}
- remove the blank lines
{quote}cat new_list | sed /^$/d > newer_list{quote}
- Cut the IP address
{quote}cat newer_list | cut -d ' ' -f 15 > final_list{quote}
- Loop through and look them up
{quote}for HOST in `cat final_list`; do host $HOST; done > hosts{quote}
- Cut to just the FQNs
{quote}cat hosts | cut -d ' ' -f 5 > final_hosts{quote}

Or perhaps you'd prefer
{code:none}
cat source | sed 's/^\[ \\\t\]*//' | sed 's/\[ \\\t\]*$//'| sed s/^Sub.*// | sed s/^Defa.*// | sed /^$/d | cut -d ' ' -f 15 > final_list
{code}

1.1 Or even better, all on one line.
{code:none}
for HOST in `cat source | sed 's/^\[ \\\t\]*//' | sed 's/\[ \\\t\]*$//'| sed s/^Sub.*// | sed s/^Defa.*// | sed /^$/d | cut -d ' ' -f 15`; do host $HOST | cut -d ' ' -f 5; done
{code}


Comments