将 curl 与 gnu-parallel 或 xarg 结合使用,循环遍历 bash 中的端口 1-65535

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

我需要进行 curl 调用,为 ip 的所有端口请求横幅(超时 5 curl -I ip:port 命令,超时 5 秒)并将结果保存到单个文件中,采用以下格式(space 分隔): "port number""second line of the pulled banner"

完成这项工作的正确 bash 脚本是什么? 此外,在 2gb 2 核 Kvm Vps 上 运行 的合理并行作业数量是多少?

P.S。我知道像 nmap 这样的脚本可以快速完成工作,但是,它们经常无法拉出横幅,而 curl 命令每次都会给我 100% 的结果。

像这样:

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