From a092c7010e6ea1c7812e481acdf279f4490f6936 Mon Sep 17 00:00:00 2001 From: Blackwhitebear8 Date: Thu, 14 Aug 2025 18:15:25 +0200 Subject: [PATCH] Update app.py --- app.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/app.py b/app.py index 28dc686..ac379bd 100644 --- a/app.py +++ b/app.py @@ -104,6 +104,21 @@ def execute_command(): if error: return jsonify({"error": error}), 400 + ipv4_commands = ['ping', 'mtr', 'traceroute'] + ipv6_commands = ['ping6', 'mtr6', 'traceroute6'] + + try: + ip = ipaddress.ip_address(target) + + if method in ipv6_commands and ip.version == 4: + return jsonify({"error": f"An IPv6 address is required for the '{method}' command."}), 400 + + if method in ipv4_commands and ip.version == 6: + return jsonify({"error": f"An IPv4 address is required for the '{method}' command."}), 400 + + except ValueError: + pass + return Response(execute_command_streaming(method, target), mimetype='text/plain') @app.route('/api/bgp_raw_lookup', methods=['POST'])