-->

Nmap - Storing Nmap Scan Data I File At A Time

Nmap - Storing Nmap Scan Data I File At A Time

The other twenty-four hours I was faced amongst a challenge where I needed to shop each nmap scan every bit its ain file. I created this quick python script to aid amongst doing this.



#!/usr/bin/python  import sys import bone import re  scanFile = 'scan.list'  def selectScan(nList, dList, sIP, eIP):  file = open('scan.list', 'r')  for business inwards file:   if '#' non inwards line:    theList = line.split(',')    nList.append(theList[0])    dList.append(theList[1])    sIP.append(theList[2])    eIP.append(theList[3].strip())   file.close()  impress  impress "Select which scan yous would similar to perform:"  impress  for i inwards range(0, len(nList)):   impress str(i+1) + ". Scan: " + nList[i] + ", Save to Directory: " + dList[i] + ", Start IP: " + sIP[i] + ", End IP: " + eIP[i]  impress  scanSelect = raw_input('Select: ')   try:   scanSelect = int(scanSelect)   scanSelect = scanSelect - 1  except:   scanSelect = 9999  provide scanSelect  def ipRangeScan(nList, dList, sIP, eIP):  dList = dList.strip(' ')  sIP = sIP.strip(' ')  eIP = eIP.strip(' ')  # nmap -sP 172.16.2.1-31 -oN test/test.subnet  impress  impress "Checking to run into if the directory exists that nosotros are saving the results to..."  if non os.path.exists(dList):   os.mkdir(dList)  # This alone plant if the scan encompasses a /24 to a /31 subnet range...  Any subnet larger that a /24 volition non live on   ipScanRange = sIP + '-' + eIP.split('.')[3]  saveFile = dList + "/" + dList + ".range"  impress "Executing 'nmap -sP " + ipScanRange + " -oN " + saveFile  execCommand = "nmap -sP " + ipScanRange + " -oN " + saveFile  c = os.system(execCommand)  def individualIPScan(nList, dList, sIP, eIP):  dList = dList.strip(' ')  sIP = sIP.strip(' ')  eIP = eIP.strip(' ')  ipList = []  # nmap -sS -sV -O 172.16.2.1 -oN test/172_16_2_1.nmap  impress  impress "Checking to run into if the directory exists that nosotros are saving the results to..."  if non os.path.exists(dList):   os.mkdir(dList)  saveFile = dList + "/" + dList + ".range"  f = open(saveFile, 'r')  designing = re.compile('^.*for\s[0-9]+(?:\.[0-9]+){3}(?:.*$|$)')  for business inwards f:   if pattern.match(line.strip()):    ip = re.findall(r'[0-9]+(?:\.[0-9]+){3}', line)    ipList = ipList + ip  f.close()   ipStartRange = int(sIP.split('.')[3])  ipEndRange = int(eIP.split('.')[3]) + 1     # If yous create non add together 1 it does non grab the final IP inwards the arrive at  for j inwards range(ipStartRange, ipEndRange):   currentIP = sIP.split('.')[0] + "." + sIP.split('.')[1] + "." + sIP.split('.')[2] + "." + str(j)   # Only scan the IP Addresses that were constitute through the previous scan...   if currentIP inwards ipList:    saveFile = dList + "/" + currentIP.replace('.','_') + ".nmap"    impress "Executing 'nmap -sS -sV -O " + currentIP + " -oN " + saveFile + "'"    execCommand = "nmap -sS -sV -O " + currentIP + " -oN " + saveFile    c = os.system(execCommand)    def main():  piece True:   pick = 0   nameList = []   dirList = []   startIP = []   endIP = []   pick = selectScan(nameList, dirList, startIP, endIP)   if ((selection < 9999) too (selection <= (len(nameList)-1))):    impress "You selected to perform the next scan: " + nameList[selection]    continueScan = raw_input('Run the inwards a higher house selected scan? (y/n): ')    if (continueScan == 'y' or continueScan == 'Y'):     ipRangeScan(nameList[selection], dirList[selection], startIP[selection], endIP[selection])     individualIPScan(nameList[selection], dirList[selection], startIP[selection], endIP[selection])    else:     impress "Error: The scan was aborted"     impress   else:    impress "Error: The pick of the scan was incorrect"    print 
 if __name__ == "__main__":     main()
It parses a file similar the next to bicycle through a diversity of scans  that yous tin stage.  To comment out a business inwards the scan.list file simply  house a # inwards the front end of the line.  I convey non tested this but I  believe yous tin non convey spaces inwards the salve to directory. 
 #Name of Scan, Save to Directory, Start IP Address, End IP Address Test1, test1, 172.16.2.1, 172.16.2.31 Test2, test2, 172.16.2.32, 172.16.2.63
 
 
 
 
 
Blogger
Disqus
Pilih Sistem Komentar

No comments

Advertiser