java - Get all IP addresses from a given IP address and subnet mask -


In Java, I need to get a list of all IP addresses contained by an IP network.

For example, having networking: 192.168.5.0/24 then the output will be (192.168.0.0 ... 192.168.5.255).

I could think of the following method but it looks dirty, is any great way? There is no function in InetAddress category.

  1. Obtain Network IP from Input IP and Subnet Mask

    Mask = (tall) (0xffffffff)

    The function 'getLongfromIp' contains the code -

    1. hosted by subnet mask

      MaxRange = (long) 0x1 < & Lt; (32-subnet mask);

    2. Get the address of Convert the IP from above step to octet string.

      Ps: I'm sure IP addresses will be in IPv4 only.

      To answer your question, resolve Apache commons.net library

        Import org.apache.commons.net.util is to use. ; SubnetUtils Utility = New Subnetuits ("192.168.1.0/24"); String [] allIps = utils.getInfo (). GetAllAddresses (); // appIps will have all IP addresses in the subnet  

      Read more:


Comments

Popular posts from this blog

apache - 504 Gateway Time-out The server didn't respond in time. How to fix it? -

c# - .net WebSocket: CloseOutputAsync vs CloseAsync -

c++ - How to properly scale qgroupbox title with stylesheet for high resolution display? -