问题描述
当我使用此命令扫描哪个IP地址时
When I use this command which IP addresed are scanned
# nmap -sP 192.168.0.120/25
CAn,当我有地址和子网时,请帮助我如何获取IP范围.因为我试图理解这一点,但是到目前为止还没有结果..谢谢您
CAn you please help me how to get the IP range when I have the addres and subnet. Because I am trying to understand this, but no result till now..Thanks in advance
推荐答案
您命令中的网络位于 CIDR 表示法.第一部分(在/
之前)定义哪个网络,第二部分定义设置多少个网络掩码. IPv4地址为4字节,即32位信息. /25
表示此地址的25位用于表示网络,而32 - 25 = 7
位则留给网络上的主机地址. /25
网络可以容纳2^7 = 128
主机,减去网络和广播地址.要获取网络地址(地址块的开头),请按地址取给定的地址,并用2^32 - 2^7
进行分配.在这种情况下(使用Python):
The network in your command is in CIDR notation. The first part (before the /
) defines which network, and the second part defines how many bits of netmask are set. An IPv4 address is 4 bytes, or 32 bits of information. /25
means that 25 bits of this address are used to denote the network, and 32 - 25 = 7
bits are left to address hosts on the network. A /25
network can hold 2^7 = 128
hosts, less the network and broadcast addresses. To get the network address (the start of your block of addresses), you take the address given and bitwise-and it with 2^32 - 2^7
. In this case (using Python):
>>> # Get the integer value of the address
>>> import struct
>>> ip = struct.unpack(">I", struct.pack("4B", 192, 168, 0, 120))[0]
>>> bin(ip)
'0b11000000101010000000000001111000'
>>> # Bitwise-and with the netmask
>>> net = ip & (2**32 - 2**7)
>>> bin(net)
'0b11000000101010000000000000000000'
>>> # Convert back to dotted-decimal
>>> struct.unpack("4B", struct.pack(">I", net))
(192, 168, 0, 0)
因此,网络地址为192.168.0.0
,您有128个地址,因此您的目标范围是192.168.0.0-192.168.0.127.
So the network address is 192.168.0.0
, and you have 128 addresses, so your target range is 192.168.0.0 - 192.168.0.127.
这篇关于如何找到IP地址范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!