Skip to content

Instantly share code, notes, and snippets.

@Becram
Last active July 3, 2019 03:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Becram/b1037b5107052ae64f4d7b90704c3177 to your computer and use it in GitHub Desktop.
Save Becram/b1037b5107052ae64f4d7b90704c3177 to your computer and use it in GitHub Desktop.
get_runing_nodes
#!/usr/bin/python
###################################################################
# Author Bikram Dhoju bikramdhoju.com.np
# Directions:
# Populate target_mac list with your list nodes
# change target_subnet to your subnet
# result is stored in output.json
####################################################################
import nmap
import datetime
import json
target_mac = ["C8:5B:76:59:74:B2",
"8C:16:45:5F:4D:AC",
"C8:5B:76:54:F8:9B",
"30:52:CB:CD:91:AC",
"C8:CB:B8:62:5E:9C",
"F0:18:98:5A:26:7E",
"54:FC:F0:97:9C:2B",
"9C:B6:D0:F8:10:4D",
"50:7B:9D:1E:BD:5B",
"8C:16:45:5F:4D:FB",
"18:DB:F2:0C:CB:96",
"E8:93:09:03:E9:39",
"50:7B:9D:35:C9:81",
"BC:9F:EF:19:F0:5F",
"50:7B:9D:35:CB:6D",
"E4:02:9B:A6:DA:A6",
"18:DB:F2:0C:CA:C6",
"A4:5D:36:9B:63:D6",
"64:A2:F9:9C:4F:68",
"04:D4:C4:5D:86:84",
"A0:1D:48:BE:0E:81",
"24:E3:14:C3:A3:44"]
target_subnet="192.168.5.0/24"
my_nodes = {}
running_hosts=[]
nm = nmap.PortScanner()
nm.scan(hosts=target_subnet, arguments='-sP')
host_list = nm.all_hosts()
#Get all running nodes
for host in host_list:
if 'mac' in nm[host]['addresses']:
running_hosts.append(nm[host]['addresses']['mac'])
for mac in target_mac:
if mac in running_hosts:
my_nodes[mac]= "True"
else:
my_nodes[mac]= "False"
x = datetime.datetime.now().strftime("%c")
output = {
"datetime": x,
"machine": [
]
}
output["machine"].append(my_nodes)
with open('output.json','a') as f:
f.write(json.dumps(output,indent=4))
print("Successfully written output to output.json file")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment