C
C
Cyril2017-03-31 10:19:06
linux
Cyril, 2017-03-31 10:19:06

How to convert an IP address?

I'm not very versed in network technology and IP addressing. But I often see the following...
For example, how to determine the subnet mask, gateway and the number of machines that "fit" in this range from the entry 10.7.4.0/30 ?
Can you show point by point (step by step) how to find out the properties of the network from such a record (IP address / number)? Gateways, number of cars, etc.
Thanks in advance!

Answer the question

In order to leave comments, you need to log in

3 answer(s)
I
iBird Rose, 2017-03-31
@belyaevcyrill

https://ru.wikipedia.org/wiki/%D0%9C%D0%B0%D1%81%D...
well, it will also be useful:
https://ru.wikipedia.org/wiki/IP
https: //ru.wikipedia.org/wiki/IPv4

R
res2001, 2017-03-31
@res2001

You will not recognize the gateway from this entry, it is indicated separately when setting up the computer.
1. In total, there are 4 bytes in the IP address (each of the 4 digits of the address is 1 byte), this is 32 bits.
2. The last digit in your entry is 30 (this is the length of the subnet mask), indicating that out of 32 bits of the address, the 30 most significant bits are the subnet mask. On your example:
subnet mask: 10.7.4.000000 - I presented the last digit in the binary system (the first ones make no sense, because they are entirely included in the mask).
The subnet mask is the same for all hosts on the subnet. In order for nodes from one network to access nodes on another network, gateways are needed. Gateways either directly have addresses on both subnets or use other intermediate gateways to access networks. This is how the Internet works at the IP level.
3. For addressing hosts on the network, you have 32-30=2 bits. In two bits, 4 values ​​can be represented: 00, 01, 10, 11. In this case, the smaller and larger value is used by the TCP / IP stack for various kinds of multicasts and broadcasts.
Based on the foregoing, only 2 values ​​\u200b\u200bare left for addressing hosts according to your example. Those. there can be 2 hosts on your subnet.

A
Alexander, 2017-03-31
@NeiroNx

addr = "10.7.4.0/30"
addr1 = addr.split('/')
hostcount = pow(2,32 - int(addr1[1]))
intmask = pow(2,32) - hostcount
dmask = [str((intmask >> (i*8)) & 0xFF) for i in range(0,4)]
dmask.reverse()
mask = ".".join(dmask)

the maximum mask is 32 bits - in binary notation 32 ones
is given a mask of 30 bits this is - in binary notation 30 ones and 2 zeros
maximum hosts for mask 0 is 2^32
maximum hosts for mask 30 is 2^(32-30) = 2^ 2 - 2 = 2
2 of which is the subnet itself and the broadcast address on that subnet.
2^32 - 2^2 numerical record of the mask
to get the byte record of the mask, you need to split the number into 4 bytes
shift by 8 bits to extract each byte
We get the mask 255.255.255.252
and the number of hosts 2
https://help.keenetic.net/hc/ en/articles/213965829...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question