update client ip retrieval
This commit is contained in:
parent
5f517e39e0
commit
333a4403e6
@ -64,6 +64,14 @@ def send_webhook(webhook_url, text_data):
|
|||||||
response.raise_for_status()
|
response.raise_for_status()
|
||||||
|
|
||||||
|
|
||||||
|
# Get client IP address
|
||||||
|
@exception_handler
|
||||||
|
def get_client_ip(request):
|
||||||
|
if not request.headers.getlist("X-Forwarded-For"):
|
||||||
|
return request.remote_addr
|
||||||
|
return request.headers.getlist("X-Forwarded-For")[0]
|
||||||
|
|
||||||
|
|
||||||
# Establish connection to network device
|
# Establish connection to network device
|
||||||
def establish_connection(device_config):
|
def establish_connection(device_config):
|
||||||
try:
|
try:
|
||||||
|
@ -3,7 +3,7 @@ from flask import (
|
|||||||
)
|
)
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from app.functions.utils import exception_handler, load_yaml, execute_command, send_webhook
|
from app.functions.utils import exception_handler, load_yaml, send_webhook, get_client_ip, execute_command,
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -58,6 +58,7 @@ def execute():
|
|||||||
|
|
||||||
# Send a webhook notification with client IP and command output
|
# Send a webhook notification with client IP and command output
|
||||||
if not result['error'] and webhook:
|
if not result['error'] and webhook:
|
||||||
send_webhook(webhook['url'], f"Client IP: `{request.remote_addr}`\nDevice: `{input_device}`\nCommand: `{input_command} -{ip_version} {input_target}`")
|
client_ip = get_client_ip(request)
|
||||||
|
send_webhook(webhook['url'], f"Client IP: `{client_ip}`\nDevice: `{input_device}`\nCommand: `{input_command} -{ip_version} {input_target}`")
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
Loading…
x
Reference in New Issue
Block a user