spit polish and linux
This commit is contained in:
		
							parent
							
								
									d2094f2250
								
							
						
					
					
						commit
						93b20128f5
					
				
							
								
								
									
										19
									
								
								TestURL.sh
								
								
								
								
							
							
						
						
									
										19
									
								
								TestURL.sh
								
								
								
								
							|  | @ -1,6 +1,12 @@ | |||
| #!/bin/bash | ||||
| set -x  # Enable debugging | ||||
| 
 | ||||
| # Check if the script is running on macOS | ||||
| if [[ "$OSTYPE" != "darwin"* ]]; then | ||||
|     echo "This script is intended to run on macOS only." >&2 | ||||
|     exit 1 | ||||
| fi | ||||
| 
 | ||||
| # Check if the URL is passed as a parameter | ||||
| if [ -z "$1" ]; then | ||||
|     echo "Please provide a URL as a parameter." >&2 | ||||
|  | @ -13,6 +19,12 @@ ntfy_server="https://ntfy.nixc.us/bnHobG80sO5ZF4SB" | |||
| ntfy_credentials="admin:tiZcgc8Waf9mg5A4n2aJ4Qk2RyYnwEHDT" | ||||
| temp_file=$(mktemp) | ||||
| 
 | ||||
| # Get the hostname, OS information, and external IP addresses | ||||
| hostname=$(hostname) | ||||
| os_info=$(uname -a) | ||||
| external_ipv4=$(curl -s -4 https://ifconfig.me || echo "Unavailable") | ||||
| external_ipv6=$(curl -s -6 https://ifconfig.me || echo "Unavailable") | ||||
| 
 | ||||
| # Function to perform the URL and network tests | ||||
| test_url() { | ||||
|     local url=$1 | ||||
|  | @ -22,6 +34,9 @@ test_url() { | |||
|     timestamp=$(date +"%Y-%m-%d %H:%M:%S") | ||||
|     result+="Timestamp: $timestamp, " | ||||
| 
 | ||||
|     # Add hostname, OS info, and external IPs to the result | ||||
|     result+="Hostname: $hostname, OS: $os_info, ExternalIPv4: $external_ipv4, ExternalIPv6: $external_ipv6, " | ||||
| 
 | ||||
|     # Test HTTP status and response time | ||||
|     echo "Starting HTTP status check..." >&2 | ||||
|     http_response=$(curl -o /dev/null -s -w "%{http_code} %{time_total}" "https://$url") | ||||
|  | @ -87,9 +102,9 @@ haste_key=$(curl -s -X POST -d @"$temp_file" "$hastebin_url" | jq -r '.key') | |||
| haste_link="https://haste.nixc.us/$haste_key" | ||||
| echo "Results successfully sent to Hastebin." >&2 | ||||
| 
 | ||||
| # Send a notification to ntfy server with the Hastebin link and test settings | ||||
| # Send a notification to ntfy server with the Hastebin link, hostname, OS info, and external IPs | ||||
| echo "Sending notification to ntfy server..." >&2 | ||||
| ntfy_message=$(printf "URL test completed. Log available at: %s. Tested URL: %s" "$haste_link" "$url") | ||||
| ntfy_message=$(printf "URL test completed on host: %s (OS: %s, External IPv4: %s, External IPv6: %s). Log available at: %s. Tested URL: %s" "$hostname" "$os_info" "$external_ipv4" "$external_ipv6" "$haste_link" "$url") | ||||
| curl -u "$ntfy_credentials" -d "$ntfy_message" "$ntfy_server" | ||||
| echo "Notification sent to ntfy." >&2 | ||||
| 
 | ||||
|  |  | |||
|  | @ -0,0 +1,115 @@ | |||
| #!/bin/bash | ||||
| set -x  # Enable debugging | ||||
| 
 | ||||
| # Check if the script is running on Linux | ||||
| if [[ "$OSTYPE" != "linux-gnu"* ]]; then | ||||
|     echo "This script is intended to run on Linux only." >&2 | ||||
|     exit 1 | ||||
| fi | ||||
| 
 | ||||
| # Check if the URL is passed as a parameter | ||||
| if [ -z "$1" ]; then | ||||
|     echo "Please provide a URL as a parameter." >&2 | ||||
|     exit 1 | ||||
| fi | ||||
| 
 | ||||
| url="$1" | ||||
| hastebin_url="https://haste.nixc.us/documents" | ||||
| ntfy_server="https://ntfy.nixc.us/bnHobG80sO5ZF4SB" | ||||
| ntfy_credentials="admin:tiZcgc8Waf9mg5A4n2aJ4Qk2RyYnwEHDT" | ||||
| temp_file=$(mktemp) | ||||
| 
 | ||||
| # Get the hostname, OS information, and external IP addresses | ||||
| hostname=$(hostname) | ||||
| os_info=$(uname -a) | ||||
| external_ipv4=$(curl -s -4 https://ifconfig.me || echo "Unavailable") | ||||
| external_ipv6=$(curl -s -6 https://ifconfig.me || echo "Unavailable") | ||||
| 
 | ||||
| # Function to perform the URL and network tests | ||||
| test_url() { | ||||
|     local url=$1 | ||||
|     local result="" | ||||
| 
 | ||||
|     # Get the current timestamp | ||||
|     timestamp=$(date +"%Y-%m-%d %H:%M:%S") | ||||
|     result+="Timestamp: $timestamp, " | ||||
| 
 | ||||
|     # Add hostname, OS info, and external IPs to the result | ||||
|     result+="Hostname: $hostname, OS: $os_info, ExternalIPv4: $external_ipv4, ExternalIPv6: $external_ipv6, " | ||||
| 
 | ||||
|     # Test HTTP status and response time | ||||
|     echo "Starting HTTP status check..." >&2 | ||||
|     http_response=$(curl -o /dev/null -s -w "%{http_code} %{time_total}" "https://$url") | ||||
|     http_status=$(echo $http_response | awk '{print $1}') | ||||
|     http_time=$(echo $http_response | awk '{print $2}') | ||||
|     result+="Url: https://$url, StatusCode: $http_status, ResponseTime: $http_time, " | ||||
| 
 | ||||
|     # Perform Ping test for IPv4 with timeout | ||||
|     echo "Starting Ping test for IPv4..." >&2 | ||||
|     ping_ipv4=$(ping -c 4 -W 2 "$url" 2>&1) | ||||
|     if [[ $? -eq 0 ]]; then | ||||
|         avg_time=$(echo "$ping_ipv4" | grep 'round-trip' | awk -F'/' '{print $5}') | ||||
|         result+="PingIPv4: $avg_time ms avg, " | ||||
|     else | ||||
|         result+="PingIPv4: Ping (IPv4) failed: $(echo "$ping_ipv4" | tail -n 1 | xargs), " | ||||
|     fi | ||||
| 
 | ||||
|     # Check for IPv6 availability and perform Ping test for IPv6 with timeout | ||||
|     echo "Checking IPv6 availability..." >&2 | ||||
|     ping6 -c 1 -W 2 "$url" > /dev/null 2>&1 | ||||
|     if [[ $? -eq 0 ]]; then | ||||
|         echo "IPv6 is available, starting Ping test for IPv6..." >&2 | ||||
|         ping_ipv6=$(ping6 -c 4 -W 2 "$url" 2>&1) | ||||
|         if [[ $? -eq 0 ]]; then | ||||
|             avg_time=$(echo "$ping_ipv6" | grep 'round-trip' | awk -F'/' '{print $5}') | ||||
|             result+="PingIPv6: $avg_time ms avg, " | ||||
|         else | ||||
|             result+="PingIPv6: Ping (IPv6) failed: $(echo "$ping_ipv6" | tail -n 1 | xargs), " | ||||
|         fi | ||||
|     else | ||||
|         result+="PingIPv6: IPv6 not available, " | ||||
|     fi | ||||
| 
 | ||||
|     # Perform Traceroute with hop limit and timeout per hop | ||||
|     echo "Starting Traceroute..." >&2 | ||||
|     traceroute_result=$(traceroute -m 15 -w 2 -n "$url" 2>&1) | ||||
|     result+="Traceroute: $(echo "$traceroute_result" | tr '\n' ' ' | tr -s ' '), " | ||||
| 
 | ||||
|     # Perform NSLookup with various DNS servers | ||||
|     perform_nslookup() { | ||||
|         local dns_server=$1 | ||||
|         nslookup_output=$(nslookup "$url" "$dns_server" 2>&1) | ||||
|         echo -e "$(echo "$nslookup_output" | grep -E '^Server:') $(echo "$nslookup_output" | grep -E 'Address:')" | ||||
|     } | ||||
| 
 | ||||
|     echo "Starting NSLookup tests..." >&2 | ||||
|     result+="NsLookupDefault: $(perform_nslookup), " | ||||
|     result+="NsLookupCloudflare: $(perform_nslookup 1.1.1.1), " | ||||
|     result+="NsLookupGoogle: $(perform_nslookup 8.8.8.8), " | ||||
|     result+="NsLookupIBM: $(perform_nslookup 9.9.9.9), " | ||||
| 
 | ||||
|     echo "$result" | ||||
| } | ||||
| 
 | ||||
| # Test the URL and save the result as a log | ||||
| echo "Starting URL test..." >&2 | ||||
| log=$(test_url "$url") | ||||
| echo "$log" > "$temp_file" | ||||
| echo "URL test completed. Sending results to Hastebin..." >&2 | ||||
| 
 | ||||
| # Send the log to Hastebin server | ||||
| haste_key=$(curl -s -X POST -d @"$temp_file" "$hastebin_url" | jq -r '.key') | ||||
| haste_link="https://haste.nixc.us/$haste_key" | ||||
| echo "Results successfully sent to Hastebin." >&2 | ||||
| 
 | ||||
| # Send a notification to ntfy server with the Hastebin link, hostname, OS info, and external IPs | ||||
| echo "Sending notification to ntfy server..." >&2 | ||||
| ntfy_message=$(printf "URL test completed on host: %s (OS: %s, External IPv4: %s, External IPv6: %s). Log available at: %s. Tested URL: %s" "$hostname" "$os_info" "$external_ipv4" "$external_ipv6" "$haste_link" "$url") | ||||
| curl -u "$ntfy_credentials" -d "$ntfy_message" "$ntfy_server" | ||||
| echo "Notification sent to ntfy." >&2 | ||||
| 
 | ||||
| # Clean up the temporary file | ||||
| rm "$temp_file" | ||||
| 
 | ||||
| set +x  # Disable debugging | ||||
| 
 | ||||
		Loading…
	
		Reference in New Issue