Created
August 14, 2014 18:24
-
-
Save kalebo/0d854f96496578bebdc3 to your computer and use it in GitHub Desktop.
A wrapper for nmap to search a range of ip ranges and report on the new hosts found
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import nmap | |
import sys | |
from time import sleep | |
HOSTS= "192.168.1.1-255" | |
class ansicolors: | |
HEADER = '\033[95m' | |
OKBLUE = '\033[94m' | |
OKGREEN = '\033[92m' | |
WARNING = '\033[93m' | |
FAIL = '\033[91m' | |
ENDC = '\033[0m' | |
def ansi_ins(string): | |
return ansicolors.OKGREEN + string + ansicolors.ENDC | |
def scannew(oldhosts): | |
nm.scan(hosts=HOSTS, arguments="-sn") | |
newhosts = [nm[x]['hostname'] for x in nm.all_hosts()] | |
return list(set(newhosts) - set(oldhosts)) | |
if __name__ == "__main__": | |
nm = nmap.PortScanner() | |
hostlist = [] | |
while True: | |
try: | |
newhosts = scannew(hostlist) | |
if newhosts != []: | |
hostlist += newhosts | |
print(ansi_ins("\nfound new hosts:\n")) | |
for i in newhosts: | |
print(i) | |
sleep(60) | |
except KeyboardInterrupt: | |
print(ansi_ins("\nDumping list of hosts to file...")) | |
hostdump = file("testsweep_dump", "w") | |
count = 0 | |
for i in hostlist: | |
if i != '': | |
hostdump.write(i + '\n') | |
count += 1 | |
print(ansi_ins("Finished writing {} hosts to file!").format(count)) | |
sys.exit(0) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment