Update app.py
This commit is contained in:
parent
a5412391d4
commit
a092c7010e
1 changed files with 15 additions and 0 deletions
15
app.py
15
app.py
|
|
@ -104,6 +104,21 @@ def execute_command():
|
||||||
if error:
|
if error:
|
||||||
return jsonify({"error": error}), 400
|
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')
|
return Response(execute_command_streaming(method, target), mimetype='text/plain')
|
||||||
|
|
||||||
@app.route('/api/bgp_raw_lookup', methods=['POST'])
|
@app.route('/api/bgp_raw_lookup', methods=['POST'])
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue