Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7007577
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T21:37:30+00:00 2026-05-27T21:37:30+00:00

Is there a specific data type for storing IP addresses in Java? I have

  • 0

Is there a specific data type for storing IP addresses in Java? I have one specific functionality requirement:

  1. Given an IP range and an IP, return true if it falls within it, false otherwise.
    For example: range 10.10.10.1-10.10.11.255 and IP 10.10.10.192 should return true.

I know of java.net.inetaddress but I believe it doesn’t give me this functionality. Any ideas?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T21:37:31+00:00Added an answer on May 27, 2026 at 9:37 pm

    An IP (IPv4) is 32 bits (the same size as an int in Java). Since you want to do comparisons using unsigned ints (if you need to support IP’s above 128.0.0.0) you need to use longs instead.

    10.10.10.1 is: (10 << 24) + (10 << 16) + (10 << 8) + 1 = 168430081
    10.10.11.255 is: (10 << 24) + (10 << 16) + (11 << 8) + 255 = 168430591
    
    10.10.10.192 is: (10 << 24) + (10 << 16) + (10 << 8) + 192 = 168430272
    

    Since 168430081 <= 168430272 && 168430272 <= 168430591, (In other words 168430272 is between 168430081 and 168430272) your IP is in the range.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a specific reason that the EF requires new data providers and can't
there is a set of data which is arranged in a specific manner (as
Is there any tool to generate test data based on specific requirements? e.g. Size,
What is the difference between these three heavily related fields? Is there one specific
I have been given a task of inputting some student data, like option 1:
I have a custom data type called StudentID , which has an implicit conversion
I have a producer / consumer queue, except that there are specific types of
I am working with a generic data structure, say MyGeneric<Type> . There is a
I have data structure which stores POD-structs (each instantiation stores a single type only,
What's the best data type to be used when storing strings, like a first

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.