Quickly determine if a domain is on a netmask

Source: Internet
Author: User

Natmask is the subnet mask, and the IP with the operation, to get a domain.

IP consists of 4 segments, example 172.25.45.10 each segment consists of a 8-bit binary

That is, 11111111.11111111.11111111.11111111, this represents 255.255.255.255.

The same subnet mask is also made up of 8-bit binary. It is divided into network bit and host bit.

172.25.45.10/24 indicates that there are 24 1 component network bits remaining 8 bits comprising the host bit.

In general, the most common subnet mask is 8 or 8 1 that is 255.0.0.0 16 1 255.255.0.0 24 1 255.255.255.0

32 1 is a broadcast address 255.255.255.255

The calculation of this is binary thinking decimal conversion.

Understand this general situation, to talk about the different. For example because of inertial thinking when we see

172.25.42.10/21 and 172.25.47.100/21 The two IP is the feeling is not a domain, because the third paragraph does not want to be the same as 42 and 47. But the fact that they are in a network segment.

Let's take the third paragraph as an example. Their respective domains should be computed in this way.

21-16=5 is all 1 of the number minus the first two paragraphs of 16 1 is the number of the third paragraph 1. The mask for the third paragraph is equivalent to 5

42 conversion to 8-bit binary 00101010 and third segment subnet Mask 5 1 that is 11111000 corresponds to the operation of the position

00101010 corresponds to decimal number is 42

11111000 Subnet Mask

00101000 the domain that corresponds to the operation of the bit and

Similarly

00101111 corresponds to decimal number is 47

11111000 Subnet Mask 00101000 corresponds to the operation of the bit and the resulting domain

A domain's judgment is to look at its network bit, so it's not in a domain in this case and the fourth paragraph is not related

You can see that 172.25.42.10/21 and 172.25.47.100/21 are in a domain.


****************************************************

So how to quickly determine whether IP is in a domain based on netmask?

172.25.42.10/21 and 172.25.47.100/21

The third segment of the network bit is 21-16=5 that host bit 8-5=3

According to the merit of the right to calculate the method can be

1 1 1 1 1 1 1 1

128 64 32 16 8 4 2 1

3 main seats is 4+2+1=7 5 network bit is 128+64+32+16+8=248

Because the subnet mask is 11111000 and the IP with the operation to calculate after the same domain in which the first 5 IP 1 is the same as the network bit, then the network bit the same premise, the change between the host bit is less than or equal to 7.


    • So when you see an IP and its subnet mask, first calculate the change in the host bit of its critical segment,

Examples 9 and 17 10 and 18 11 and 19 they were in the first and second paragraphs, but their host bits were consistent.

9 11111111 10000000) 00000000 0000000

17 11111111 11111111) 10000000 0000000


Their critical segment host bit is 127 critical segment is to be able to determine whether in a domain of key satin netmask 0 to 8 is the first paragraph 8 to 16 is the second paragraph 16 to 24 is the third paragraph 24 to 32 is the fourth paragraph


Compute the key segment of the host bit 172.25.42.10/21 and 172.25.47.100/21 their key segment is the third segment of the host bit is 7 then first determine whether the key segment of the IP is less than the host bit, in the example 42 and 47 difference bit 5 is less than 7 So it's possible to be in a network segment. If greater than 7 is definitely not a domain.


③ if less than 7 is possible in one domain.

0-7

8-15

16-23

24-31

32-39

.

.

.

248-255

can find patterns

The host bit is 0 to 7 is 8 a loop

So in the premise of less than or equal to 7 can use the IP/8 of the key segment to see if their quotient is the same as in a domain, but not a domain.

Example 42/8=5 47/8=5 can all be 5 so together that 42 and 48 is not a domain.


This can be done in an arithmetic way to quickly judge.

Quickly determine if a domain is on a netmask

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.