Advertisement
Guest User

Nmap + Python / Valdinei dos Santos

a guest
Mar 12th, 2010
314
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.61 KB | None | 0 0
  1. #! /bin/env python
  2. #!-*- coding: utf-8 -*-
  3.  
  4. from commands import getstatusoutput
  5.  
  6. logFile='ipmac.txt'
  7.  
  8. nets='192.168.200.1-255'
  9.  
  10. command="sudo nmap -sP %s | egrep -i '(Host|MAC)' >> %s" % (nets, logFile)
  11.  
  12. status, output = getstatusoutput(command)
  13.  
  14. newLines = ''
  15. if int(status) == 0:
  16.     print 'ok'
  17.     for line in file(logFile).readlines():
  18.         if 'Host ' in line:
  19.             newLines += line.rstrip()+" "
  20.         else:
  21.             newLines += line.strip()+"\n"
  22. else:
  23.     print "Problema com o comando nmap"
  24.     print output
  25.  
  26. FILE = open(logFile, 'w')
  27. FILE.writelines(newLines)
  28. FILE.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement