-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnetsentinel.py
More file actions
46 lines (39 loc) · 1.21 KB
/
netsentinel.py
File metadata and controls
46 lines (39 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
from flask import Flask, render_template
import nmap
import socket
import ipaddress
app = Flask(__name__)
def scan_network():
hostname = socket.gethostname()
local_ip = socket.gethostbyname(hostname)
network = ipaddress.ip_network(local_ip + '/24', strict=False)
nm = nmap.PortScanner()
nm.scan(hosts=network.with_prefixlen, arguments='-O')
devices = []
for host in nm.all_hosts():
ip = host
try:
name = nm[host].hostname() or socket.gethostbyaddr(host)[0]
except Exception:
name = "Unknown"
os = "Unknown"
if 'osmatch' in nm[host] and nm[host]['osmatch']:
os = nm[host]['osmatch'][0]['name']
devices.append({'ip': ip, 'name': name, 'os': os})
return devices
@app.route('/')
def index():
return render_template('radar.html')
@app.route('/scan')
def scan():
devices = scan_network()
return render_template('mainpage.html', devices=devices)
if __name__ == '__main__':
import threading
import time
import webbrowser
def open_browser():
time.sleep(2)
webbrowser.open('http://127.0.0.1:5000')
threading.Thread(target=open_browser, daemon=True).start()
app.run(debug=False)