How can i calculate ip address range from subnet mask - networking

When I use this command which IP addresed are scanned
# nmap -sP 192.168.0.120/25
How can I get the IP range when I have the addres and subnet. Because I am trying to understand this, but no result till now..Please help me..Thank a lot

You can use ipcalc, a nice *nix tool to guide you:
~ $ ipcalc 192.168.0.120/25
Address: 192.168.0.120 11000000.10101000.00000000.0 1111000
Netmask: 255.255.255.128 = 25 11111111.11111111.11111111.1 0000000
Wildcard: 0.0.0.127 00000000.00000000.00000000.0 1111111
=>
Network: 192.168.0.0/25 11000000.10101000.00000000.0 0000000
HostMin: 192.168.0.1 11000000.10101000.00000000.0 0000001
HostMax: 192.168.0.126 11000000.10101000.00000000.0 1111110
Broadcast: 192.168.0.127 11000000.10101000.00000000.0 1111111
Hosts/Net: 126 Class C, Private Internet

192.168.0.120
This says that the IP address is 192.168.0.120.
/25
This says that the netmask is 25 bits long. As an IPv4 address is 32 bits, that leaves 7 bits for the address. The lowest IP address in the range is given by masking out the bottom 7 bits, and the highest by adding 127 (=27-1) to that.

Related

Using SNMP retrieve IP and MAC addresses of directly connected machines to a SNMP Device

How to get connected machine's IP and Mac of SNMP device.
ARP cache is not giving correct details.
Example for Linux shell commands (no tag for other languages or Windows at time of writing)
Providing that the machine you want to query does run a SNMP Daemon ( generally snmpd from Net-SNMP under Linux ) and that you know how/are allowed to speak to it ( version 1, 2c or 3 with various community names or usernames/passwords/encoding for v3 ) you may issue the following SNMP requests:
For the test I started a snmpd on a CentOS 7 virtual machine whose main address was 192.168.174.128.
I choose port 1610 over the traditional 161 in order not to sudo or to setcap (snmpd). The snmpd.conf file contents is out of the range of this question.
This first one for IPs
snmptable -v 2c -c private 192.168.174.128:1610 ipAddrTable
SNMP table: IP-MIB::ipAddrTable
ipAdEntAddr ipAdEntIfIndex ipAdEntNetMask ipAdEntBcastAddr ipAdEntReasmMaxSize
127.0.0.1 1 255.0.0.0 0 ?
192.168.122.1 3 255.255.255.0 1 ?
192.168.174.128 2 255.255.255.0 1 ?
The second command (with 3 columns only printed) for MAC
snmptable -v 2c -c private 192.168.174.128:1610 ifTable | awk -c '{print $1 "\t" $2 "\t\t" $6}'
SNMP table:
ifIndex ifDescr ifPhysAddress
1 lo up
2 ens33 0:c:29:53:aa:c6
3 virbr0 52:54:0:e6:6b:2f
4 virbr0-nic 52:54:0:e6:6b:2f
When we check under CentOS 7 we get
ifconfig
ens33: ... mtu 1500
inet 192.168.174.128 netmask 255.255.255.0 broadcast 192.168.174.255
inet6 ...
ether 00:0c:29:53:aa:c6 netmask 255.0.0.0
...
lo: ... mtu 65536
inet 127.0.0.1
...
virbr0: ... mtu 1500
inet 192.168.122.1 netmask 255.255.255.0 broadcast 192.168.122.255
ether 52:54:00:e6:6b:2f ...
...
Bonus shell command:
snmptranslate -Oaf IF-MIB::ifTable
.iso.org.dod.internet.mgmt.mib-2.interfaces.ifTable
and
snmptranslate -Oaf IP-MIB::ipAddrTable
.iso.org.dod.internet.mgmt.mib-2.ip.ipAddrTable
I do not know why/if there is a single table holding both information.

Total IP to CIDR Conversion

I know Start IP Address aka Network Id and also total IP Address as well but how I can calculate its CIDR or End IP from it without knowing Subnet Mask.
Example
Start IP : 192.168.8.0
Total IP : 1024
1024 IP addresses is a /22 CIDR and the network mask would be 255.255.252.0
You can go to http://ipconvertertools.com/cidr2ipranges and convert 192.168.8.0/22 to IP range.
You will get:
Network Address First IP Last IP Subnet Mask Broadcast Total IP's
192.168.8.0 192.168.8.1 192.168.11.254 255.255.252.0 192.168.11.255 1021
Just add few IP's so you will have 1024 total IP
How to convert manually:
Convert IP to binary -> 11000000101010000000100000000000
Convert total IP -> 10000000000
======
11000000101010000000100000000000 +
10000000000 =
----------------------------------
11000000101010000000110000000000 = 192.168.12.0
(where is 0 remains zero. If in the same column there is 1, it becomes 1)

ipcalc - why it can't give correct network size by default

I found ipcalc didn't give correct network size when not specify the netmask,
In below result, it take the hosts count as 254, but not 2^24 -2,
eric#ePc:~$ ipcalc 101.12.12.12
Address: 101.12.12.12 01100101.00001100.00001100. 00001100
Netmask: 255.255.255.0 = 24 11111111.11111111.11111111. 00000000
Wildcard: 0.0.0.255 00000000.00000000.00000000. 11111111
=>
Network: 101.12.12.0/24 01100101.00001100.00001100. 00000000
HostMin: 101.12.12.1 01100101.00001100.00001100. 00000001
HostMax: 101.12.12.254 01100101.00001100.00001100. 11111110
Broadcast: 101.12.12.255 01100101.00001100.00001100. 11111111
Hosts/Net: 254 Class A
But, if I give netmask by hand ipcalc 101.12.12.12/8, then it gives correct result.
I want to know: did ipcalc do this not properly? Or, ipv4 address are used in this way in real world?
classless inter domain routing was invented last century, since then it has not been practical to derive a netmask from a network address,
101.0.0.0 used to be a class A network, I don't know if it still is, neither does ipcalc.

How to tell which IP is valid only based on the given subnet mask

I'm looking for a way to tell which IP is valid only based on the given subnet mask.
For example : given the subnet mask : 255.255.255.240, is 195.206.108.25 a valid IP? Why?
IP: 195.206.108.25
MASK: 255.255.255.240 (/28)
255.255.255.255
- 255.255.255.240
---------------------
0. 0. 0. 15
Network: 195.206.108.0/28
Usable hosts: 195.206.108.1-195.206.108.14
Broadcast: 195.206.108.15
Network: 195.206.108.16/28
Usable hosts: 195.206.108.17-195.206.108.30
Broadcast: 195.206.108.31
So 195.206.108.25 is a valid IP address of the 195.206.108.16/28 network. (correct me if I'm wrong)

Creating subnets

Using the following IP Range can anyone break this down into 3 subnets for me displaying IP's in each range and their subnet masks please
Current setting below needs breaking into 3 the start off the range needs to be the smallest subnet.
IP Range 192.168.1.128 - 192.168.1.159
Gateway 192.168.1.129
Subnet 255.255.255.224
Usable 192.168.1.132 - 192.168.1.158
Many thanks
Using the SubNetMask 255.255.255.248 you should quarter the IP-Range. So the new nets are:
1) IP: 192.168.1.128
Usable: 192.168.1.129 - 192.168.1.134 (.135 is Broadcast)
2) IP: 192.168.1.136
Usable: 192.168.1.137 - 192.168.1.142 (.143 is Broadcast)
3) IP: 192.168.1.144
Usable: 192.168.1.145 - 192.168.1.150 (.151 is Broadcast)
4) IP: 192.168.1.152
Usable: 192.168.1.153 - 192.168.1.158 (.159 is Broadcast)

Resources