How to get Subnet
mask address of local system using Java programming?
相关问题
- Delete Messages from a Topic in Apache Kafka
- Jackson Deserialization not calling deserialize on
- How to maintain order of key-value in DataFrame sa
- StackExchange API - Deserialize Date in JSON Respo
- Difference between Types.INTEGER and Types.NULL in
I devised an IPv4 only solution that is simple enough. I needed that to generate netmask for subnetworks here in order to delegate those subnets correctly. I know I could have generated a table of the 32 possible masks, but I prefered to get it computed each time.
So here is my solution.
You just call it with the IP and the prefix you want to use, it will generate the netmask for you.
In summary, a method to obtain the mask would be like this:
the netmask of the first address of the localhost interface:
a more complete approach:
/24 means 255.255.255.
Here is an answer, how to get a submask from WIFI connection: link
I adapted it for my needs, and here it is: