Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
#!/usr/bin/python
import os
import netifaces
import netaddr
interface = netifaces.gateways()['default'][netifaces.AF_INET][1]
ipaddress = netifaces.ifaddresses(interface)[netifaces.AF_INET][0]['addr']
netmask = netifaces.ifaddresses(interface)[netifaces.AF_INET][0]['netmask']
cidr = netaddr.IPNetwork('%s/%s' % (ipaddress,netmask))
network = netaddr.IPNetwork('%s/%s' % (cidr.network,netmask))
command = '/usr/bin/nmap'
output = '/root/output.txt'
export = '/root/export.txt'
os.system(command+' -sn '+str(network)+' -oN '+output)
f = open(output,'r')
w = open(export,'w')
for line in f:
out = line.split(' ')
vdr = line.split('(')
if(out[0] == '#' and out[3] == 'scan'):
date = out[5]+' '+out[6]+' '+out[7]+' '+out[9]+' '+out[8]
if(out[0] == 'Nmap' and out[4][:-1] != ipaddress):
w.write('date='+date+'|scanner='+ipaddress+'|address='+out[4][:-1]+'|')
if(out[0] == 'MAC'):
w.write('mac='+out[2]+'|vendor='+vdr[1][:-2]+'\n')
f.close()
w.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment