<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>ARP欺骗检测软件 - 网络安全防御</title>
    <link rel="stylesheet" href="style.css">
</head>
<style>
</style>
<body>
   <div id="box">
    <h1>ARP欺骗检测软件 - 网络安全防御</h1>
       <div class="buttons">
    <a href="{{ url_for('register') }}">注册</a>
    <a href="{{ url_for('login') }}">登录</a>
   </div>
   </div>
</body>
</html>
点击登录如何跳转登录页面python
from flask import Flask, render_template, request, redirect, url_for, jsonify
import os
import time
import sys
import platform
from scapy.all import *
<p>app = Flask(<strong>name</strong>)
app.secret_key = 'secret_key'
@app.route('/')
def index():
return render_template('index.html')</p>
<p>@app.route('/register', methods=['GET', 'POST'])
def register():
if request.method == 'POST':
with open(&quot;user.txt&quot;, &quot;a&quot;) as f:
f.write(request.form['username'] + ' ' + request.form['password'] + &quot;\n&quot;)
flash(&quot;注册成功!&quot;)
return redirect(url_for('login'))
return render_template('register.html')</p>
<p>@app.route('/login', methods=['GET', 'POST'])
def login():
if request.method == 'POST':
with open(&quot;user.txt&quot;, &quot;r&quot;) as f:
users = f.readlines()
for user in users:
if user.split()[0] == request.form['username'] and user.split()[1] == request.form['password']:
session['username'] = request.form['username']
flash(&quot;登录成功!&quot;)
return redirect(url_for('func'))
flash(&quot;用户名或密码错误!&quot;)
return render_template('login.html')</p>
<p>@app.route('/func')
def func():
if 'username' not in session:
return redirect(url_for('login'))
return render_template('func.html')</p>
<p>@app.route('/icmp_flood')
def icmp_flood():
sniff_filter = &quot;icmp&quot;
sniff_timeout = 10
sniff_count = 0
sniff_packets = sniff(filter=sniff_filter, timeout=sniff_timeout)
for packet in sniff_packets:
sniff_count += 1
if sniff_count &gt; 100:
flash(&quot;检测到ICMP flood攻击!&quot;)
with open(&quot;detection_log.txt&quot;, &quot;a&quot;) as f:
f.write(&quot;ICMP flood攻击检测 - 检测结果:检测到ICMP flood攻击\n&quot;)
else:
flash(&quot;未检测到ICMP flood攻击!&quot;)
with open(&quot;detection_log.txt&quot;, &quot;a&quot;) as f:
f.write(&quot;ICMP flood攻击检测 - 检测结果:未检测到ICMP flood攻击\n&quot;)
return redirect(url_for('func'))</p>
<p>@app.route('/tcp_attack')
def tcp_attack():
sniff_filter = &quot;tcp&quot;
sniff_timeout = 10
sniff_count = 0
sniff_packets = sniff(filter=sniff_filter, timeout=sniff_timeout)
for packet in sniff_packets:
sniff_count += 1
if sniff_count &gt; 100:
flash(&quot;检测到TCP攻击!&quot;)
with open(&quot;detection_log.txt&quot;, &quot;a&quot;) as f:
f.write(&quot;TCP攻击检测 - 检测结果:检测到TCP攻击\n&quot;)
else:
flash(&quot;未检测到TCP攻击!&quot;)
with open(&quot;detection_log.txt&quot;, &quot;a&quot;) as f:
f.write(&quot;TCP攻击检测 - 检测结果:未检测到TCP攻击\n&quot;)
return redirect(url_for('func'))</p>
<p>@app.route('/arp_spoofing')
def arp_spoofing():
sniff_filter = &quot;arp&quot;
sniff_timeout = 10
sniff_count = 0
sniff_packets = sniff(filter=sniff_filter, timeout=sniff_timeout)
for packet in sniff_packets:
sniff_count += 1
if sniff_count &gt; 100:
flash(&quot;检测到ARP欺骗攻击!&quot;)
with open(&quot;detection_log.txt&quot;, &quot;a&quot;) as f:
f.write(&quot;ARP欺骗攻击检测 - 检测结果:检测到ARP欺骗攻击\n&quot;)
else:
flash(&quot;未检测到ARP欺骗攻击!&quot;)
with open(&quot;detection_log.txt&quot;, &quot;a&quot;) as f:
f.write(&quot;ARP欺骗攻击检测 - 检测结果:未检测到ARP欺骗攻击\n&quot;)
return redirect(url_for('func'))</p>
<p>@app.route('/detect_attack')
def detect_attack():
with open(&quot;clients.txt&quot;, &quot;r&quot;) as f:
clients = f.readlines()
for client in clients:
ip = client.split()[0]
mac = client.split()[1]
sniff_filter = &quot;arp and src host &quot; + ip
sniff_timeout = 10
sniff_count = 0
sniff_packets = sniff(filter=sniff_filter, timeout=sniff_timeout)
for packet in sniff_packets:
sniff_count += 1
if sniff_count &gt; 100:
flash(&quot;检测到攻击源IP地址为&quot; + ip + &quot;,MAC地址为&quot; + mac + &quot;!&quot;)
with open(&quot;detection_log.txt&quot;, &quot;a&quot;) as f:
f.write(&quot;警告&quot; + &quot;检测到攻击源IP地址为&quot; + ip + &quot;,MAC地址为&quot; + mac + &quot;!\n&quot;)
else:
flash(&quot;未检测到攻击源!&quot;)
with open(&quot;detection_log.txt&quot;, &quot;a&quot;) as f:
f.write(&quot;提示&quot; + &quot;未检测到攻击源!\n&quot;)
return redirect(url_for('func'))</p>
<p>@app.route('/scan_network')
def scan_network():
network = &quot;192.168.31.0/24&quot;
arp_request = ARP(pdst=network)
broadcast = Ether(dst=&quot;ff:ff:ff:ff:ff:ff&quot;)
arp_broadcast = broadcast/arp_request
answered_list = srp(arp_broadcast, timeout=1, verbose=False)[0]
clients = []
for element in answered_list:
client = {&quot;ip&quot;: element[1].psrc, &quot;mac&quot;: element[1].hwsrc}
clients.append(client)
with open(&quot;clients.txt&quot;, &quot;w&quot;) as f:
for client in clients:
f.write(client[&quot;ip&quot;] + ' ' + client[&quot;mac&quot;] + &quot;\n&quot;)
flash(&quot;扫描完成!&quot;)
return redirect(url_for('func.html'))</p>
<p>@app.route('/view_detection_log')
def view_detection_log():
with open(&quot;detection_log.txt&quot;, &quot;r&quot;) as f:
detection_log = f.read()
flash(detection_log)
return redirect(url_for('func.html'))</p>
<p>if <strong>name</strong> == '<strong>main</strong>':
app.run()</p>
ARP欺骗检测软件 - 网络安全防御