Search code examples
bashcurlxargsgnu-parallel

Using curl with gnu-parallel or xarg, to loop through ports 1-65535 in bash


I need to make a curl call, to request a banner (timeout 5 curl -I ip:port command, with 5s timeout) for all the ports of an ip and save the results into a single file, in the following format (space delimited): "port number" "second line of the pulled banner"

What would be the correct bash script to do the job? Also, what's the reasonable amount of the parallel jobs to run, on the 2gb 2-core Kvm Vps?

P.S. I know the are scripts like nmap, to do the job fast, but, they often fail in pulling the banners, where as the curl command gives me 100% result, each time.


Solution

  • Something like this:

    parallel 'r=$(timeout 5 curl -l 192.168.0.1:{} | sed -ne "2p"); echo "{} $r"'  ::: {1..65535}