Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Easy way to verify an IP #?  RSS feed

 
Matt Senecal
Ranch Hand
Posts: 255
  • Mark post as helpful
  • send pies
  • 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)
 
karl koch
Ranch Hand
Posts: 388
  • Mark post as helpful
  • send pies
  • 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
 
Joel Peach
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!