我正在学习bash以进行渗透测试,所以我从对我来说很有用的东西开始。我创建了一个脚本,可以根据需要扫描整个网络。但是在脚本结尾,我想做这个Ips的Nmap。
那就是问题,不知道如何执行。
time=$(date +"%T")
ip=(192.168.0)
echo -e "Scan started at $time"
for x in $(seq 1 254); do
ping -c 1 $ip.$x | grep "from" &
done
echo -n "Would you like to do NMAP scan (y/n)? "
read nmap
if [ "$nmap" != "${nmap#[Yy]}" ] ;then
#here i guess have to be something
else
#here i guess have to be something
fi
如果用户选择“ y”,则NMAP应该扫描IP地址,这些IP地址会被实时探测。
答案 0 :(得分:0)
这是有关如何一起使用ping和nmap的简单解决方案
#!/bin/bash
ipfile=$(mktemp) # create tmpfile for online ip's
trap 'rm -f "$ipfile"' EXIT # rm tmpfile on exit
BASE="192.168.0" # define your IP base
for (( i=1; i <= 254; i++ )); do
ip="$BASE.$i"
printf "Scanning %s " "$ip"
# check if ip is online
if ping -c 1 "$ip" | grep "from" >/dev/null; then
printf "online\n"
# write ip's into tmpfile
printf "%s\n" "$ip" >> "$ipfile"
else
printf "offline\n"
fi
done
echo -n "Would you like to do NMAP scan (y/n)? "
read -r answer
if [ "$answer" = "y" ]; then
# check all ip's in tmpfile with nmap
nmap -iL "$ipfile"
fi