#!/bin/bash # # Small script to create multiple listeners with 'nc' # # Execute script with 'nohup' into the background and forward # output to /dev/null for minimal interference in console: # nohup sudo ./create_listener.sh "4005 4006 4007 4008 4009" >/dev/null 2>&1 & # # Using quotes is only necessary for multiple listening ports! # # To terminate just force kill 'nohup' process and all 'nc' processes: # sudo pkill -9 -f listener.sh; sudo pkill -9 -f nc # # Üllar Seerme # Use the following if you want hardcoded ports # declare -a ports=(4005 4006 4007 4008 4009) IFS=" " read -r -a ports <<< "$1" # Keep running until killed manually while true; do for i in "${ports[@]}"; do echo "Testing port: {$i}" if ! ss -tlp | grep -q :"$i"; then echo "No process listening on port ${i}; creating listener" nc -l -p "$i" & else echo "Process already listening on port ${i}; skipping" fi done # Adjust according to preference # Without this it will just needlessly load the CPU way too much sleep 5; done