#!/bin/bash
echo -n "Enter the domain name > "
read name
dig -t ns "$name" | cut -d ";" -f3 | cut -d ":" -f2| grep ns | cut -f6 > registerfile.txt;
cat registerfile.txt | while read line; do dig axfr "@$line" "$name"; done | cut -d"." -f-4 > nmap.txt这件事一直到这部分。下面,它可能与行和名称参数不匹配。该如何改变呢?
cat nmap.txt | while read line; do if [ "$line" == "$name" ]; then host "$line"; fi; done > ping.txt
cat ping.txt | cut -d " " -f4 | while read line; do if [[ "$line" =~ ^[0-9]+$ ]]; then nmap -sS "$line";fi ;done发布于 2017-04-11 22:49:08
目前还不清楚到底哪里出了问题,但这里有一个重构,希望至少能将您推向正确的方向。
#!/bin/bash
read -p "Enter the domain name > " name
dig +short -t ns "$name" |
tee registerfile.txt |
while read line; do
dig axfr "@$line" "$name"
done |
cut -d"." -f-4 |
tee nmap.txt |
while read line; do
if [ "$line" = "$name" ]; then
host "$line"
fi
done > ping.txt
cut -d " " -f4 ping.txt |
grep -E '^[0-9]+$' |
xargs -r -n 1 nmap -sS您在评论中关于if [ "$line" = "$name" ]; then host "$line"; fi不起作用的评论表明,这里的逻辑是错误的。目前,它检查每一行是否与原始域名相同,然后在这些情况下一遍又一遍地查找它,这似乎是一件很奇怪的事情;但只考虑到代码和“不工作”,很难说出它到底要完成什么任务。如果你真的想要别的东西,你需要对你所需要的东西更加具体。也许你实际上是在寻找类似
... tee nmap.txt |
# Extract the lines which contain $name at the end
grep "\.$name\$" |
xargs -n 1 dig +short |
tee ping.txt |
grep -E '^[0-9]+$' ...多个静态命名文件的使用是反模式的;显然,如果这些文件没有外部用途,只需取出tee命令并运行整个管道,不需要在输出文件之间插入。如果您确实需要这些文件,那么在每次运行时覆盖它们似乎是有问题的--也许在文件名中添加一个唯一的日期戳后缀?
https://stackoverflow.com/questions/43356950
复制相似问题