Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Network Auditor v0.2
- #Sheldon Alman
- #sheldonalman at gmail.com
- #This script runs an nmap scan on the specified IP addresses and outputs
- #the results to a XML file that will be compared with a previous scan's results
- #using yandiff.
- import os, time, string, sys, os.path
- from datetime import date
- current = ""
- previous = ""
- def main():
- global current
- global previous
- network = "192.168.1.1-254" #Change so that this can be read from command-line
- today = date.today().isoformat() #Sets today variable to MM-DD-YYYY format
- xmlpath = "xml/nmap-" + network + "-" + today + ".xml"
- nmapArgs = ["nmap","-A","-PN",network, "-oX", xmlpath]
- pid = os.fork()
- if pid < 0:
- print "Fork failed"
- sys.exit(-1)
- if pid == 0:
- #Child 1
- if not os.path.isdir("xml"):
- os.mkdir("xml",0755)
- #nmap execution
- if not os.path.isfile("xml/baseline.xml"):
- pid2 = os.fork()
- if pid2 == 0:
- #Child 2. No Parent code executed.
- os.execlp("nmap", "nmap", "-A", "-PN",network,"-oX", "xml/baseline.xml")
- pid3 = os.fork()
- if pid3 == 0:
- #Child 3
- os.execvp("nmap", nmapArgs)
- else:
- #Parent 3
- #yandiff execution
- os.wait() #Wait for child to complete execution
- current = "xml/" + os.listdir("xml")[-1]
- previous = "xml/" + os.listdir("xml")[-2]
- yandiffOutFile = "diff_files/yandiff-" + network + "-" + today + ".xml"
- yandiffArgs = ["yandiff", "-b", previous, "-o",current, "-f", "xml","--output-file",yandiffOutFile, "-s", "yandiff.xsl"]
- if not os.path.isdir("diff_files"):
- os.mkdir("diff_files",0755)
- os.execvp("yandiff", yandiffArgs)
- sys.exit(0)
- else:
- #Parent 1
- os.wait() #Wait for child to complete execution
- if not os.path.isdir("html"):
- os.mkdir("html",0755)
- current = "xml/" + os.listdir("xml")[-1]
- previous = "xml/" + os.listdir("xml")[-2]
- os.system("xsltproc -o html/" + "nmap-" + network + "-" + today + ".html" + " /usr/local/bin/../share/nmap/nmap.xsl " + current)
- os.system("xsltproc -o html/" + "yandiff-" + network + "-" + today + ".html" + " yandiff.xsl" + " diff_files/yandiff-" + network + "-" + today + ".xml")
- if __name__ == "__main__":
- main()
Advertisement
Add Comment
Please, Sign In to add comment