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 6624427
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T21:39:07+00:00 2026-05-25T21:39:07+00:00

I am using the sun.net.util.IPAddressUtil package to check whether the string contains a valid

  • 0

I am using the sun.net.util.IPAddressUtil package to check whether the string contains a valid IPv4 and IPv6 address or not.

Code Snippet is:-

String ipv4addr="200";

    if(IPAddressUtil.isIPv4LiteralAddress(ipv4addr))
    {
        System.out.println("valid ipv4 address");
    }
    else
    {
        System.out.println("not valid");

    }

But for addresses such as 200 and 300 it is still saying it is a valid IPv4 address, which it isn’t.
When I used the same package and checked for IPV6 address using :-

String ipv6addr="200";

    if(IPAddressUtil.isIPv6LiteralAddress(ipv6addr))
    {
        System.out.println("valid ipv6 address");
    }
    else
    {
        System.out.println("not valid");

    }

I get the correct result. However, IPv4 does not seem to be working or may be I am using it incorrectly. Please guide me. I don’t want to use regex for IPv4 validation…

  • 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-25T21:39:08+00:00Added an answer on May 25, 2026 at 9:39 pm

    There’s a reason you’re getting a “valid” result: 200 is a valid IPv4 address.

    See, to the computer, an IPv4 address is just a 32-bit number. The dots are entirely for our convenience, because we humans suck at memorizing big precise numbers. But they don’t have to be there; there are rules about how an address gets parsed depending on how many parts it has.

    When an address consists of one number, it’s considered a 32-bit number, and each byte is 8 bits of that number. If you were to parse "200" as an IP address, it would be equivalent to 0.0.0.200. Likewise, "2130706433" would be equivalent to 127.0.0.1.

    There are also standards for when an address has two parts like 0.200 (first part is the first byte, and the second part is a 24-bit number representing the other 3 bytes), and even 0.0.200 (first two numbers are bytes, the last part is 16 bits and takes up the other 2 bytes). The “unusual” formats are leftovers from the days of IP address classes, but almost all software that has to parse addresses will understand them. (If you pop open your browser and go to http://1249739112* or even http://74.125.33128*, for example, Google’s home page will come up.)

    * See the comments for clickable links. Thanks, “link validator”. 😛

    See http://download.oracle.com/javase/6/docs/api/java/net/Inet4Address.html or http://www.perlmonks.org/?node_id=221512, or http://en.wikipedia.org/wiki/IPv4#Address_representations, for some more details.

    Java understands these formats as well (as does .net, as well as any decent OS), and parses the address correctly whether it contains 1, 2, 3, or 4 parts.

    If you want to check that a would-be address actually looks like “xxx.xxx.xxx.xxx”, then you’ll probably want to explicitly check that using a pattern, or using a validation library that considers 32-bit numbers as invalid addresses (even though they are valid). I wouldn’t bother, though — if you use the lookup functions provided, you can accept an address in any standard format and it will work.

    (All this mess changes with IPv6; there’s a much stricter format, and you can’t just type in some 36-digit number and expect it to work. But the platform still knows how to parse an address, and you should trust it to do so.)

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

Sidebar

Related Questions

I have implemented simple com.sun.net.httpserver.HttpServer application using one of examples in the internet. Server
I'm using com.sun.net.httpserver.HttpServer in my project. However, it seems that the server leaks connections
Using Sun Glassfish Enterprise server v2.1.1 I am using alternatedocroot via sun-web.xml for my
I am new to Unix and am using sun solaris (v10 I think). I
I'm writing a Java application that runs on Linux (using Sun's JDK). It keeps
Using the Sun Java VM 1.5 or 1.6 on Windows, I connect a non-blocking
I have been using com.sun.org.apache.xpath.internal.XPathAPI for some time and it seems to work ok.
Using the stock Sun 1.6 compiler and JRE/JIT, is it a good idea to
I am using http://java.sun.com/jsp/jstl/fmt tag library for outputting messages from Message Resource Bundle which
Using IE 7, JDK 1.6 and Sun Web server 7. Inside the jsp form,

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.