Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
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' % (,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):
if(out[0] == 'MAC'):
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment