Centos 扫描整个ip范围/子网以查找端口80是否打开?

Centos 扫描整个ip范围/子网以查找端口80是否打开?,centos,port,Centos,Port,我需要一种快速有效的方法来扫描端口80打开的ip范围 46.105.0.51 46.105.0.72 46.105.0.91 46.105.0.7 46.105.0.15 例如,如果我想扫描OVH IP范围“46.105.0.0/16”,我需要它扫描该范围内的每个IP,并输出端口80打开时每个IP的列表 46.105.0.51 46.105.0.72 46.105.0.91 46.105.0.7 46.105.0.15 我需要扫描多个子网,我需要它输出到一个文件 编辑:我还在我的专用机箱上运

我需要一种快速有效的方法来扫描端口80打开的ip范围

46.105.0.51
46.105.0.72
46.105.0.91
46.105.0.7
46.105.0.15
例如,如果我想扫描OVH IP范围“46.105.0.0/16”,我需要它扫描该范围内的每个IP,并输出端口80打开时每个IP的列表

46.105.0.51
46.105.0.72
46.105.0.91
46.105.0.7
46.105.0.15
我需要扫描多个子网,我需要它输出到一个文件

编辑:我还在我的专用机箱上运行CentOS,带有1Gbit上行线路。

:

…将为您提供在
tcp/80
上响应的主机列表以及相应的
nmap
输出

  • -Pn
    :跳过ping测试,因为您只关心开放端口
  • --open
    :仅返回端口已打开的IP
用一点
awk
ing(和
grep
,因为我很懒,在
awk
方面不是很在行-一个
awk
master能帮我解决这个问题吗?),你可以得到IP列表:

nmap -Pn -p80 --open 46.105.0.0/16 | grep 46.105 | awk '{print  $5}NF == 6{print $6}'
nmap
还具有以特定格式输出到文件的选项,或者您可以只
输出到文件:

nmap -Pn -p80 --open 46.105.0.0/16 | grep 46.105 | awk '{print  $5}NF == 6{print $6}' > output.txt

对于阅读这篇文章而碰巧无法访问nmap的任何人来说,这里有一个快速而基本的方法来扫描网络上的端口80。这个脚本只需要ipcalc,它很可能是可用的

#!/bin/bash
# easier to end the script if signal is caught
trap exit 1 2 3 4 5 6 7 8
# define a function that emulate netcat by opening a port to an ip via file descriptor
netcat() {
        exec 20<>/dev/tcp/${1}/${2}
}

# using ipcalc, get the nwtork address and the broadcast address and make both $NETWORK and $BROADCAST available to the script
export $(ipcalc -b -n $1)

# Convert the NETWORK and BROADCAST from dotted notation to hex
printf -v startHexIP "%0.2x%0.2x%0.2x%0.2x" $(tr '\.' ' ' <<< $NETWORK)
printf -v endHexIP "%0.2x%0.2x%0.2x%0.2x" $(tr '\.' ' ' <<< $BROADCAST)

# computations are done in decimal so we need decimal representation of the BROADCAST address to control the list of IP addresses
printf -v endDecIP "%d" 0x${endHexIP}

# legitimate IP addresses start from NETWORK ADDRESS + 1 and end at BROADCAST ADDRESS - 1
for((i=$(( 0x$startHexIP + 1 )); i<$endDecIP; i++)); do
        # $i is in decimal. we need to convert to hex
        printf -v hexI "%8.8x" $i
        # convert hex to dotted notation.
        printf -v ip "%d.%d.%d.%d" 0x${hexI:0:2} 0x${hexI:2:2} 0x${hexI:4:2} 0x${hexI:6:2}
        if (netcat $ip 80 > /dev/null 2>&1); then
                echo $ip
        fi
done

这只需要4行脚本就可以完成

创建名为“scanall”的脚本文件(仅为示例) 并复制下面的代码,它将扫描/24网络。(1-254)

因此,如果我想让scanall 192.168.1.0/24找到打开的端口22,只需运行 (在chmod+x之后)

然后结果会显示出来

192.168.1.1 [192.168.1.2] 22 (ssh): open
192.168.1.2 [192.168.1.2] 22 (ssh): Connection refused
.
.
192.168.1.183 [192.168.1.183] 22 (ssh): Operation timed out
192.168.1.184 [192.168.1.184] 22 (ssh): Connection refused 
192.168.1.185 [192.168.1.185] 22 (ssh) open                
192.168.1.186 [192.168.1.186] 22 (ssh): Operation timed out
192.168.1.187 [192.168.1.187] 22 (ssh): Operation timed out
192.168.1.188 [192.168.1.188] 22 (ssh): Operation timed out
.
.
192.168.1.254 [192.168.1.254] 22 (ssh): Operation timed out

我使用你的命令时出错。非法参数-P,使用-P0、-PI、-PB、-PE、-PM、-PP、-PA、-PU、-PT或-PT80(或TCP探测器目标端口所需的任何数字)退出!我还需要将其输出到.txt文件。好的,将
-Pn
替换为
-P0
。输出到文件应该很简单,只需将
>output.txt
添加到命令末尾即可。请尝试
nmap-P0-p80——打开46.105.0.0/16 | grep 46.105 | awk'{print$5}NF==6{print$6}>output.txt
好的,非常感谢。到目前为止工作得很好,但它是这样导出的:vpsxxx.ovh.net(46.105.x.x)上有趣的端口:端口状态服务80/tcp过滤http我如何摆脱所有无用的垃圾,只拥有IP?总noob与grep和nmap。谢谢你有什么版本的nmap(
nmap--version
)?
--open
标志应仅返回
打开的主机,而不是
过滤的主机或
关闭的主机。
# SCRIPT NAME: scanall
# USAGE      : scanall SUBNET PORT # put up to 3rd octet
#
# EXAMPLE    : scanall 192.168.1 80
#                       subnet  port

END=254
for i in $(seq 1 $END); do
    netcat -vz -w1 $1.$i $2;
done

# script will put 4th octet starting from 1 to 254 each line of netcat test.
# edit END to 128 if you want ip range 1~128 to be checked which is /25
bash:~$ scanall 192.168.1 22
192.168.1.1 [192.168.1.2] 22 (ssh): open
192.168.1.2 [192.168.1.2] 22 (ssh): Connection refused
.
.
192.168.1.183 [192.168.1.183] 22 (ssh): Operation timed out
192.168.1.184 [192.168.1.184] 22 (ssh): Connection refused 
192.168.1.185 [192.168.1.185] 22 (ssh) open                
192.168.1.186 [192.168.1.186] 22 (ssh): Operation timed out
192.168.1.187 [192.168.1.187] 22 (ssh): Operation timed out
192.168.1.188 [192.168.1.188] 22 (ssh): Operation timed out
.
.
192.168.1.254 [192.168.1.254] 22 (ssh): Operation timed out