Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
212 views
in Technique[技术] by (71.8m points)

bash - Replace specific command line automatically and save the results

I would like to get range port scan results from one of my server IP by using a single port scan command line. (Don't recommend me other port scanners like nmap which has a port range scan feature please :( )

Command-line examples are following (I just want to scan a specific IP with multiple ports)

root@localhost: serverstats IP:Port

root@localhost: serverstats 1.1.1.1:2000
Result/output↓↓↓
root@localhost:  {"online": true}

What I would like to do

root@localhost: serverstats 1.1.1.1:2200  ?    serverstats 1.1.1.1:2500  (About 300 ports)

Command result/output -> root@localhost: {"online": true}

Scan 300 port range on a single IP with the above single port scan command and save the command results/outputs automatically in a text file like the following :)

300ports.log ↓

{"online": true}
{"online": false}
{"online": false}
{"online": true}
{"online": false}
..... (and remaining 295 port scan results)

Thank you!

question from:https://stackoverflow.com/questions/65915030/replace-specific-command-line-automatically-and-save-the-results

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
IP="1.1.1.1"
for (( i=1;i<=300;i++ ));
do 
   serverstats "$IP:$i"
done | grep -E '{"online": (false|true)}' > 300ports.log

Loop 300 times to generate port numbers and use these to generate the serverstats commands. Pipe the output to grep to search for the output along with "false" or "true" and redirect the grepped output to 300port.log


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...