• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Easy way to verify an IP #?

 
Ranch Hand
Posts: 255
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is there an easy way to verify that an IP number the user entered is valid in form? I mean, I know that you can parse the string and check for 3 periods and that there aren't more than 3 numbers between periods, but I was wondering if there was a simpler way.
I tried using InetAddress.getByName(String), but getByName will actually alter the String it is passed to make it fit! (ex: 121.0.55 becomes 121.0.0.55, 121 becomes 0.0.0.121)
 
Ranch Hand
Posts: 388
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
not any that i know of.
i did it by splitting it at the '.' and then check if the values are 0 <= value <= 255 and there are four of them. this should be ebough. care must be taken also if a port is entered...split the string again at the ':' and check if an integer is located behind (bettween 1 and 2^16-1 -i think)
k
 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Someone should really write a component to do this. There are actually many more numeric representations that are allowed for specifying IP addresses, including different bases (octal, hex, etc).
See the following site for more information on the alternate IP address representations.
http://www.pc-help.org/obscure.htm
Best of luck!
-Joel
 
karl koch
Ranch Hand
Posts: 388
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
nice link....didnt know this.
however the dotted op format is the one used everywhere and i dont see a need in supporting obscure "features" as dWord representation. or is there a reason ?
k
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic