Article 5DDKM Variable in Bash Script - single nmap search

Variable in Bash Script - single nmap search

by
orangepeel190
from LinuxQuestions.org on (#5DDKM)
Hi All,

I am wishing to obtain certain details from an Nmap search on a remote machine - and use these details in a script.

Rather than running 4 Nmap searches in the bash script, I am hoping that I am able to simply run 1 search (to help speed things up) and from that single search, grep/awk out the required information into certain areas as needed.

Here is an extract from my bash script thus far - albeit a little rough and a work in progress

Code:# Nmap Source
nmap_source=`sudo nmap -sS -sV -oG - $input -p $port`

# Resolve Host Name
nmap_hostname=`(cat $nmap_source) | awk '$4=="Status:" && $5=="Up" {print $3}' | tr -d '()'`

#Resolve IP
nmap_ip=`(cat $nmap_source) | awk '$4=="Status:" && $5=="Up" {print $2}'`

# Resolve OS
nmap_os=`(cat $nmap_source) | grep 'open'`

# Host up ?
nmap_up=`(cat $nmap_source) | grep 'host up'`I am having issues in getting the script to source and read the original output (nmap_source - being the single search) and then use this information in the other tasks to grep/awk out the required information (which is still a work in progress - so the above lines probably won't awk/grep correctly as yet).

Rather than write the output (nmap_source) to a file for the task, then delete this file upon exiting the script, I was hoping to simply call upon the source information within the script, then filter out the information.

Is CAT the way to recall this information in the individual tasks (obtain IP, hostname etc) or is there an alternative that I am missing? Don't think "echo" would work - then again - maybe my syntax is a little out?

I was hoping to only use nmap for this single task search as I am thinking that it would be able to obtain the required information in a single search, rather than using nc and dig as extra lines in the script.

Thanks for your feedbacklatest?d=yIl2AUoC8zA latest?i=cAlgNaJJmd0:qjboVS9gzac:F7zBnMy latest?i=cAlgNaJJmd0:qjboVS9gzac:V_sGLiP latest?d=qj6IDK7rITs latest?i=cAlgNaJJmd0:qjboVS9gzac:gIN9vFwcAlgNaJJmd0
External Content
Source RSS or Atom Feed
Feed Location https://feeds.feedburner.com/linuxquestions/latest
Feed Title LinuxQuestions.org
Feed Link https://www.linuxquestions.org/questions/
Reply 0 comments