What I'm doing is specifying a range of IP addresses for nmap, say (192.168.0.0-50), to scan and for each IP it scans I need to use the output in different functions.
Here is a bit of code from what I'm doing:
def revLookup(ips):
revCmd = "nmap -R -sP " + ips
revargs = shlex.split(revCmd)
revOut = subprocess.Popen(revargs, shell=False, stdout=subprocess.PIPE)
for rline in revOut.stdout:
if "Nmap scan report for " in rline:
nmapNmIp = rline.strip("Nmap scan report for")
rname, rip = nmapNmIp.split(" ")[0], nmapNmIp.split(" ")[-1]
if rname.strip() == rip.strip():
rname = "NO Name Provided"
revNmapName = rname.split('.', 1)[0]
rip = re.sub('[\(\)]', '', rip.strip())
elif "MAC Address: " in rline:
rnmapmac = rline.split(': ', 1)[-1]
rnmapmac = rnmapmac.split(" ")[0]
return revNmapName, rip, rnmapmac
The value that is returning is only the last value from the list. I have other functions that are using the various values to create other information, but I need to produce these one by one. I can do this is if I create one long messy function, I know that's not the right way.
Any advice is appreciated, thanks.