def all_tests(): if request.method == 'POST': instance_type = '' endpoint = request.form['endpoint'] print(endpoint) checks_to_run = request.form.getlist('checks') print(checks_to_run) port = request.form['port'] print(port) if endpoint == '' and len(checks_to_run) == 0 and port == '0': return render_template( 'index.html', endpoint_message="Please enter an IP or Endpoint", checkbox_message="Please select at least one test to run", dropdown_message="Please select a port to test") if endpoint == '': return render_template( 'index.html', endpoint_message="Please enter an IP or Endpoint") if len(checks_to_run) == 0: return render_template( 'index.html', checkbox_message="Please select at least one test to run") if len(checks_to_run ) >= 1 and 'telnet' in checks_to_run and port == '0': return render_template( 'index.html', checkbox_message="Please select a port to test with telnet") if instance.determine_if_ip_or_endpoint(endpoint) == 'IP': instance_type = instance.determine_instance_type_by_ip(endpoint) elif instance.determine_if_ip_or_endpoint(endpoint) == 'Endpoint': instance_type = instance.determine_instance_type_by_endpoint( endpoint) elif instance.determine_if_ip_or_endpoint( endpoint) == 'Custom Endpoint': print('Custom endo') instance_type = instance.determine_instance_type_by_endpoint( endpoint) elif instance.determine_if_ip_or_endpoint( endpoint) == 'Invalid Endpoint': return render_template( 'index.html', endpoint_message="Please enter a valid endpoint") elif instance.determine_if_ip_or_endpoint(endpoint) == 'Private IP': return render_template('index.html', endpoint_message="Please enter a public IP") elif instance.determine_if_ip_or_endpoint(endpoint) == 'Invalid IP': return render_template('index.html', endpoint_message="Please enter a valid IP") ping_out = [] trace_out = [] tel_out = [] ns_out = [] if instance_type == 'Not a valid AWS resource': return render_template('index.html', endpoint_message="Not a valid AWS resource") elif instance_type == 'EC2': for i in range(len(checks_to_run)): if checks_to_run[i] == 'ping': ping_out = ping.perform_ping(endpoint) elif checks_to_run[i] == 'traceroute': trace_out = traceroute.trace_route_of_instance(endpoint) elif checks_to_run[i] == 'nslookup': ns_out = nslookup.name_to_ip(endpoint) print(ns_out) elif checks_to_run[i] == 'telnet': port = int(port) tel_out = telnet.check_if_port_open(host=endpoint, port=port) elif instance_type == 'RDS': for i in range(len(checks_to_run)): if checks_to_run[i] == 'ping': ping_out = [ 'ICMP Packets are blocked on RDS', ['ICMP Packets are blocked on RDS'], ['ICMP Packets are blocked on RDS'] ] elif checks_to_run[i] == 'traceroute': trace_out = [ 'ICMP Packets are blocked on RDS', ['ICMP Packets are blocked on RDS'], ['ICMP Packets are blocked on RDS'] ] elif checks_to_run[i] == 'nslookup': ns_out = nslookup.name_to_ip(endpoint) print(ns_out) elif checks_to_run[i] == 'telnet': port = int(port) tel_out = telnet.check_if_port_open(host=endpoint, port=port) print(tel_out) print(instance_type) return render_template('results.html', ping_output=ping_out, telnet_output=tel_out, traceroute_output=trace_out, nslookup_output=ns_out, port=port)
def test_ping_without_reply(self): response = ping.perform_ping('127.0.0.0') self.assertFalse('Reply' in response[1])
def test_ping_without_reply_endpoint(self): response = ping.perform_ping('www.googley.com') self.assertFalse('Reply' in response[1])
def test_fail_ping(self): response = ping.perform_ping('www.googlfasdfaey.com') print(response) self.assertFalse('Request timed out.' in response)
def test_ping_with_reply_endpoint(self): response = ping.perform_ping('www.google.com') self.assertTrue('Reply' == 'Reply')