SHARE
TWEET

Nmap + Python / Valdinei dos Santos

a guest Mar 12th, 2010 245 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top