forked from rkutsel/netbox-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfping.py
24 lines (20 loc) · 902 Bytes
/
fping.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import sys, time, requests, json
from fping_api import *
time_stamp = time.strftime("%Y-%m-%d %H:%M:%S")
netbox_set = ipv4_address()
fping_set = set()
with open('fping_hosts') as fping:
for scanned_ini in fping:
scanned_mod = scanned_ini.rstrip('\n')
scanned = fping_set.add(scanned_mod + '/32')
for scanned in fping_set:
if scanned in netbox_set:
continue
else:
ip_add = {"status": "2", "description": "Scanned and marked as alive", "custom_fields": {"Scanned":"1"}, "address": str(scanned)}
ip_link = "https://HOSTNAME/api/ipam/ip-addresses/" #Replace HOSTNAME with NetBox URL/IP
ip_post = requests.post(ip_link, json=ip_add, headers=headers, verify=False)
log = open('logs/fping_run.log', 'a')
log_msg = time_stamp + ':' + 'Host:' + str(scanned) + ' has been added.' + '\n'
log.write(log_msg)
log.close