Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- __license__ = 'GPL-3'
- __version__ = '0.1'
- __author__ = 'irenicus09'
- __date__ = '18/05/2012'
- """
- This simple script relies on Nmap to discover hosts on LAN,
- finds hosts using the Ping scan technique, parses & presents data
- in a clear, readable format for commandline users.
- Note: Edit the value of IP Range as required.
- """
- import subprocess, os
- from clint.textui import colored
- # Edit the following values as required
- ipRange = '192.168.0.1/24'
- fileName = 'Hosts.txt'
- # Don't edit this, list for storing result
- hostList = []
- def FindHosts():
- if ((os.path.exists(fileName)) == False):
- cmd = subprocess.Popen("nmap -sP %s | grep -o -P '(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})' >> %s" % (ipRange, fileName), shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
- cmd.communicate()
- else:
- os.remove(fileName)
- FindHosts()
- def PrintHosts():
- try:
- fileObject = open(fileName, 'r+')
- hostList = fileObject.readlines()
- fileObject.close()
- count = 0
- print colored.green('=')*50
- length = '\t\t%d HOSTS FOUND' % len(hostList)
- print colored.cyan(length)
- print colored.green('=')*50
- for i in hostList:
- count += 1
- value = '%s)'.ljust(4) % count
- i = '%s'.ljust(15) % (i.strip())
- print colored.green(value) + colored.red(i)
- except (Exception):
- print '\n[!] Error opening file %s' % fileName
- if __name__ == '__main__':
- FindHosts()
- PrintHosts()
Advertisement
Add Comment
Please, Sign In to add comment