Last active
February 10, 2019 08:36
-
-
Save usrme/3fafd289779020b96beb5499ac4019bd to your computer and use it in GitHub Desktop.
Small script to create multiple listeners with 'nc'
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment