是否可以使用linux工具同时向多个主机发送http-get请求?
现在我做了
wget -O- http://192.168.1.20/get_data-php > out.log但我需要请求所有的192.168.1.0/17 IP。
发布于 2020-07-07 14:43:49
#!/bin/sh
rm address.txt allout.txt # remove old file with addresses and contents
nmap -n -sn 192.168.1.0/17 -oG - | awk '/Up$/{print $2}' > address.txt # get all active hosts and store into a file address.txt
while IFS="" read -r add || [ -n "$add" ]
do
wget -q -O- http://"$add"/get_data-php > out"$add".log & # for every address create file with wget content
done < address.txt
wait
cat out*.log > allout.txt # put all .log file contents to allout.txt
rm -r out*.log # remove all created .log files发布于 2020-07-07 17:51:27
最简单的方法是使用bash支撑展开。
wget -O- http://192.168.{0..127}.{1..254}/get_data-php >>out.log..。如果性能不是问题(因为它将按顺序运行请求)。
当然,有一些方法可以并行运行请求,但我想这超出了这个问题的范围。
发布于 2020-08-04 02:08:01
基于Drejc的回答,但避免了对临时文件的干扰,并且更好地处理了低于主机数量的进程限制(例如,如果您有1000 s的主机)。
#!/bin/sh
nmap -T5 -n -sn 192.168.1.0/17 -oG - |
awk '/Up$/{print $2}' |
parallel -j0 wget -q -O- http://{}/get_data-php > allout.txthttps://stackoverflow.com/questions/62777037
复制相似问题