Skip to content

Instantly share code, notes, and snippets.

@remonsec
Created October 25, 2023 09:20
Show Gist options
  • Save remonsec/35bc2989b235165a5f9da0218e2b0690 to your computer and use it in GitHub Desktop.
Save remonsec/35bc2989b235165a5f9da0218e2b0690 to your computer and use it in GitHub Desktop.
A Bash script for reformatting RustScan greppable output into a usable line-by-line text file, ideal for integration with other tools.
#!/bin/bash
# Usage
# bash rustscan-converter.sh ports.txt
# Check if the input file exists
if [ ! -f "$1" ]; then
echo "Input file '$1' not found."
exit 1
fi
# Read the input file line by line
while IFS= read -r line; do
# Extract the IP address and port numbers using awk
ip=$(echo "$line" | awk -F ' -> ' '{print $1}')
ports=$(echo "$line" | awk -F ' -> ' '{print $2}' | sed 's/\[//;s/\]//;s/,/\n/g')
# Loop through the port numbers and print in the desired format
while IFS= read -r port; do
echo "$ip:$port"
done <<< "$ports"
done < "$1"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment