Results 1 to 7 of 7
  1. #1
    d3n1s is offline Member
    Join Date
    Apr 2011
    Posts
    80
    Rep Power
    0

    Default Browse through IP range?

    Hi everyone

    I'm trying to write a class that takes a beginning IP and an end IP (say 10.0.1.0 and 10.0.2.255). I basically need a nextIp() method in there that will start at the first ip (the start IP provided in the constructor) and return the next IP every time it's invoked until the end IP is reached. I have tried breaking down the IPs into integers for each octet but this is quickly starting to hurt my brain!

    I know there are tons of libraries out there, is there something that exists already that i could use to achieve that goal? My goal is to eventually create an object for each machine it finds that responds to a ping and import them in my DB.

    Thanks!

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,001
    Rep Power
    33

    Default Re: Browse through IP range?

    What have you tried?
    Do you have any specific questions or problems?
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    13

    Default Re: Browse through IP range?

    The dotted quad format for IPv4 addresses is nothing more than a convenience for humans. The IPv4 addresses are unsigned 32 bit integers, period! So the easiest way would be to convert each IP address to an int and simply increment (taking into account the sign bit of course). From there you need to decide how to remember the last IP returned, if it is important in your model.

    Regards,
    Jim
    Last edited by jim829; 01-25-2017 at 02:23 AM.
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  4. #4
    d3n1s is offline Member
    Join Date
    Apr 2011
    Posts
    80
    Rep Power
    0

    Default Re: Browse through IP range?

    so far i have tried literally re-inventing the wheel, as in storing each octet of the start, end and current IPs in int variables and incrementing each one until it reaches 255 and then resetting it to 0 and incrementing the previous octet by 1 etc. Sounds like i need to look into what Jim suggested about converting the IPs to an unsigned int. I will see what i can find. If you have an example of what i could do to accomplish that that would be great.

    Thanks guys

  5. #5
    d3n1s is offline Member
    Join Date
    Apr 2011
    Posts
    80
    Rep Power
    0

    Default Re: Browse through IP range?

    Found exactly what i was looking for here :

    https://www.mkyong.com/java/java-con...ecimal-number/

    i ended up converting my range start and end IPs to long values, keeping track of the current and incrementing it by 1 each time nextIP() is called. I simply return the current value converted to a string and it works perfectly!

    Thanks

  6. #6
    gozzy is offline Member
    Join Date
    Jan 2017
    Posts
    46
    Rep Power
    0

    Default Re: Browse through IP range?

    It's usually more convenient if you can apply a netmask using CIDR notation for these situations. See Scan IP range

  7. #7
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    13

    Default Re: Browse through IP range?

    Actually, CIDR does not really apply in this situation. The OP just wants to get the next IP address within
    a range, not the next network number within a range. So just treating the IP addresses as a 32 bit unsigned
    integer is all that is necessary.

    So as I understand the OP's requirement is to list all IP's from say
    10.1.0.2/32 to 10.2.0.255/32

    Regards,
    Jim





    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

Similar Threads

  1. MQ Visual Browse 1.6.0
    By java software in forum Java Software
    Replies: 0
    Last Post: 05-05-2012, 06:36 PM
  2. MQ Visual Browse 1.5.5
    By java software in forum Java Software
    Replies: 0
    Last Post: 12-29-2011, 05:35 PM
  3. GUI and Browse
    By kingkongkill in forum New To Java
    Replies: 2
    Last Post: 04-13-2011, 02:36 PM
  4. Browse for and append
    By looselispssinkships in forum New To Java
    Replies: 0
    Last Post: 03-19-2010, 10:25 AM
  5. MP3s and Browse
    By AndrewM16921 in forum New To Java
    Replies: 2
    Last Post: 08-13-2009, 04:45 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •