Skip to content

Commit

Permalink
v1.0.4: Add exception handling to network module
Browse files Browse the repository at this point in the history
This update enhances the reliability of the network module by adding exception handling to various methods. While previously, methods like ping_from_server, telnet_from_server, etc., would crash the application on encountering an error, now, they catch general exceptions and return the error message. This prevents app crashing and facilitates troubleshooting. Moreover, input validation has been added to ensure the IP address or DNS name entered is correct before execution, increasing overall function stability.
  • Loading branch information
Aidaho12 committed May 19, 2024
1 parent ed8926d commit 49e0dbe
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
4 changes: 4 additions & 0 deletions app/modules/roxywi/nettools.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

def ping_from_server(server_from: str, server_to: str, action: str) -> Response:
action_for_sending = ''
if server_to == '':
raise Exception('warning: Wrong IP address or DNS name')

def paint_output(generated):
yield '<div class="ping_pre">'
Expand Down Expand Up @@ -112,6 +114,8 @@ def nslookup_from_server(server_from: str, dns_name: str, record_type: str) -> s


def whois_check(domain_name: str) -> str:
if domain_name == '':
raise Exception('warning: Wrong IP address or DNS name')
try:
whois_data = json.loads(str(whois.whois(domain_name)))
except Exception as e:
Expand Down
20 changes: 16 additions & 4 deletions app/routes/main/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,25 @@ def nettools_check(check):
domain_name = common.is_ip_or_dns(request.form.get('nettools_whois_name'))

if check == 'icmp':
return nettools_mod.ping_from_server(server_from, server_to, action)
try:
return nettools_mod.ping_from_server(server_from, server_to, action)
except Exception as e:
return str(e)
elif check == 'tcp':
return nettools_mod.telnet_from_server(server_from, server_to, port_to)
try:
return nettools_mod.telnet_from_server(server_from, server_to, port_to)
except Exception as e:
return str(e)
elif check == 'dns':
return nettools_mod.nslookup_from_server(server_from, dns_name, record_type)
try:
return nettools_mod.nslookup_from_server(server_from, dns_name, record_type)
except Exception as e:
return str(e)
elif check == 'whois':
return jsonify(nettools_mod.whois_check(domain_name))
try:
return jsonify(nettools_mod.whois_check(domain_name))
except Exception as e:
return str(e)
else:
return 'error: Wrong check'

Expand Down

0 comments on commit 49e0dbe

Please sign in to comment.