A bitwise mask that shows which part of the IP address is shared by all computers in the subnetwork and is used to identify them all together in some larger network. The IP address part that is not flagged by this mask identifies individual computers in the subnetwork.

Netmask can be specified either in quad-dotted decimal representation like 255.255.254.0 (means the seven lower bits identify computers in subnetwork) or, together with IP address, as a number of the high bits used by the larger network and not by subnetwork (192.168.80.0/23, the same).

The bitwise AND operation between mask and IP address results the address of the network itself, and the remainder identifies the computer LAN connector within that network.

83 questions

### How to calculate the IP range when the IP address and the netmask is given?

When a IP-Range is written as aaa.bbb.ccc.ddd/netmask (CIDR Notation) I need to calculate the first and the last included ip address in this range with C#. Example: Input: 192.168.0.1/25 Result: 192.168.0.1 - 192.168.0.126
Anheledir
• 4,337
• 7
• 32
• 34

### Given the IP and netmask, how can I calculate the network address using bash?

In a bash script I have an IP address like 192.168.1.15 and a netmask like 255.255.0.0. I now want to calculate the start address of this network, that means using the &-operator on both addresses. In the example, the result would be 192.168.0.0.…
Christian
• 2,903
• 4
• 31
• 34

### Calculate CIDR from a given netmask - Java

Is there a way to calculate a CIDR given a Sub net mask using any Java lib/function/trick?? I have been looking for a while and all I can find is from CIDR -> Netmask and I need it the other way arround Netmask -> CIDR ... Im not that handy on…
PzP01
• 93
• 1
• 5

### Bash - Convert netmask in CIDR notation?

Example: I have this netmask: 255.255.255.0 Is there, in bash, a command or a simple script to convert my netmask in notation /24?
Alex_DeLarge
• 325
• 1
• 2
• 8

### Standard/safe way to check if IP address is in range/subnet

I have a small piece of code that converts a 32-bit unsigned integer (ie: uint32_t) into a set of four 8-bit fields, treats it like an IP address, and then reports to the client if it falls within a predetermined range of IP addresses. I've already…
Cloud
• 18,753
• 15
• 79
• 153

### Java & Windows 7: Reliably getting IPv4 netmask?

I've run into a known bug with Java 6 on Windows. My understanding is that the normal way to get the netmask is to look up the network prefix length and do some bit shifts. The problem is that on Windows the prefix length is often returned…
Timothy Miller
• 1,527
• 4
• 28
• 48

### How to convert a CIDR prefix to a dotted-quad netmask in Python?

How can I convert a CIDR prefix to a dotted-quad netmask in Python? For example, if the prefix is 12 I need to return 255.240.0.0.
planetp
• 14,248
• 20
• 86
• 160

### DhcpInfo isn't responding the netmask in Android Lollipop

Yesterday I update my nexus 5 to lollipop and my application stops working, after a little investigation I found the problem the DhcpInfo isn't is returning null on the netmask variable. I couldn't find any alternative to this class.
Carlos EduardoL
• 670
• 6
• 14

### How can I get netmask from Android device?

I need to get the netmask and ip from the Android so I can calculate all the IP's within my subnet range. I've been searching and so far I've found this: Programmatically getting the gateway and subnet mask details The problem is that it doesn't…
sergi
• 969
• 5
• 14
• 22

### How to determine netmask of active interface in Objective-C on a Mac?

I'm trying to determine the network segment my Macbook is in, because I then want to scan this segment for active hosts (basic IP scanner) by using the CFHost class. Therefore I need the IP and Netmask of my active interface. This is how I get the…
Martin
• 351
• 1
• 4
• 11

### Need to break down a IP subnet

I am trying to write a script which breaks down subnets larger(not greater than /16) than /24 to a /24 subnet. Eg : 10.10.10.0/23 should give me 10.10.10.0/24 and 10.10.11.0/24 My logic is to first scan for the CIDR mask. if smaller than 24, then…
skd
• 45
• 1
• 5

### Android, detect local IP and subnet mask for WiFi, both while tethering and connected to access point

I need to detect the local IP address and subnet mask on the WiFi network, on an Android device (in order to proper calculate the UDP broadcast address strictly for the local subnet). When the device is connected to an Access Point, the following is…
GozzoMan
• 782
• 9
• 23

### Efficient way to test if bitwise IPv6 netmask is contiguous

I need to store IP addresses/netmasks in an in_addr/in6_addr struct. For IPv4 I use the following code to test if the netmask is contiguous: ((((~netmask + 1) & (~netmask)) != 0) && (netmask != 0)) I was wondering if there is a smart way to do the…
evelina
• 157
• 1
• 1
• 8

I want to convert netmask to wildcard mask with netaddr library so the input is netmask = 255.255.255.0 and the output is wildcard = 0.0.0.255 or the input is netmask = 255.255.255.252 and the output is wildcard = 0.0.0.3
• 177
• 1
• 1
• 10