sheldonalman

Network Auditor v0.2

Jul 6th, 2013
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.45 KB | None | 0 0
  1. #Network Auditor v0.2
  2. #Sheldon Alman
  3. #sheldonalman at gmail.com
  4. #This script runs an nmap scan on the specified IP addresses and outputs
  5. #the results to a XML file that will be compared with a previous scan's results
  6. #using yandiff.
  7.  
  8. import os, time, string, sys, os.path
  9. from datetime import date
  10.  
  11. current = ""
  12. previous = ""
  13.  
  14. def main():
  15.     global current
  16.     global previous
  17.  
  18.     network = "192.168.1.1-254" #Change so that this can be read from command-line
  19.     today = date.today().isoformat() #Sets today variable to MM-DD-YYYY format
  20.     xmlpath = "xml/nmap-" + network + "-" + today + ".xml"
  21.     nmapArgs = ["nmap","-A","-PN",network, "-oX", xmlpath]
  22.  
  23.     pid = os.fork()
  24.     if pid < 0:
  25.         print "Fork failed"
  26.         sys.exit(-1)
  27.     if pid == 0:
  28.         #Child 1
  29.         if not os.path.isdir("xml"):
  30.             os.mkdir("xml",0755)
  31.         #nmap execution
  32.         if not os.path.isfile("xml/baseline.xml"):
  33.             pid2 = os.fork()
  34.             if pid2 == 0:
  35.                 #Child 2.  No Parent code executed.
  36.                 os.execlp("nmap", "nmap", "-A", "-PN",network,"-oX", "xml/baseline.xml")
  37.  
  38.         pid3 = os.fork()
  39.         if pid3 == 0:
  40.             #Child 3
  41.             os.execvp("nmap", nmapArgs)
  42.         else:
  43.             #Parent 3
  44.             #yandiff execution
  45.             os.wait() #Wait for child to complete execution
  46.             current = "xml/" + os.listdir("xml")[-1]
  47.             previous = "xml/" + os.listdir("xml")[-2]
  48.             yandiffOutFile = "diff_files/yandiff-" + network + "-" + today + ".xml"
  49.             yandiffArgs = ["yandiff", "-b", previous, "-o",current, "-f", "xml","--output-file",yandiffOutFile, "-s", "yandiff.xsl"]
  50.             if not os.path.isdir("diff_files"):
  51.                 os.mkdir("diff_files",0755)
  52.             os.execvp("yandiff", yandiffArgs)
  53.             sys.exit(0)
  54.     else:
  55.         #Parent 1
  56.         os.wait() #Wait for child to complete execution
  57.         if not os.path.isdir("html"):
  58.             os.mkdir("html",0755)
  59.         current = "xml/" + os.listdir("xml")[-1]
  60.         previous = "xml/" + os.listdir("xml")[-2]
  61.         os.system("xsltproc -o html/" + "nmap-" + network + "-" + today + ".html" + " /usr/local/bin/../share/nmap/nmap.xsl " + current)
  62.         os.system("xsltproc -o html/" + "yandiff-" + network + "-" + today + ".html" + " yandiff.xsl" + " diff_files/yandiff-" + network + "-" + today + ".xml")
  63.        
  64. if __name__ == "__main__":
  65.     main()
Advertisement
Add Comment
Please, Sign In to add comment