gpt-3.5-turbo-0613· OpenAI
Arena Human Preference 55K
write a bash script to read a CSV file, and for each line, open a tcp connection to the…
- User
write a bash script to read a CSV file, and for each line, open a tcp connection to the IP address in column a, with the port in column b, with a timeout of 2 sec, and write to stdout if the connection is successful, rejected, or timed out.
- Assistant
Sure! Here's a bash script that reads a CSV file, opens a TCP connection to the IP address and port specified in each line, and prints the connection status to stdout:
#!/bin/bash # Function to test TCP connection test_connection() { local ip=$1 local port=$2 local timeout=$3 local status # Try connecting to the IP address and port (echo >/dev/tcp/$ip/$port) &>/dev/null # Get the exit code of the previous command status=$? # Check the exit code and print the connection status if [[ $status -eq 0 ]]; then echo "Connection to $ip:$port successful" elif [[ $status -eq 1 ]]; then echo "Connection to $ip:$port rejected" else echo "Connection to $ip:$port timed out" fi } # Read the CSV file while IFS=, read -r ip port; do # Call the test_connection function for each line test_connection "$ip" "$port" 2 done < your_csv_file.csv
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.