• 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

verification of ip-addresses

 
Ranch Hand
Posts: 456
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
good morning,

till now i'm using objects of InetAddress to create and verify ip-addresses. if the client enters a ip-address, i check if i can derive a new InetAddress object. if the ip is invalid ("333.0.0.0"), InetAddress will return a null value.

(my experience tells me that it is always better to work with specialized object, if they are provided)

but now i discovered that InetAddress returns null for 127.0.0.1 (localhost), and probably for all ip-values below 127.x.x.x too. as far as i know this would not be correct for meeting my requirement, as a user can at least use localhost to let (one?) client and server run on the same machine, and probably also setup a local network with ip's below 127.x.x.x

how are you verifying the ip-input? are you doing this string based? or is there a better way?

many thanks for your help,
jan
 
Ranch Hand
Posts: 442
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

how are you verifying the ip-input?



I didn't, and lost nothing in that section if that means anything. If you're hell bent on doing it then maybe attempt to connect, there may be a better way but that's foolproof. Well almost, the machine may not be available when the user does the configuration. Sooooo, IMO, allow absolutely anything, I did a range check on ports, but allowed every one of them within the range, it was documented to be up to the user to know which ports they can/can't use or deal with the message and try again. On the plus side with allowing everything a user can type the name of the host instead of pinging "jan" to see the ip.
 
Jan Groth
Ranch Hand
Posts: 456
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks for you answer!

i decided to build a little LocalIp class, with a appropriate constructor and a isCorrect() method. less then 30 lines of code, and a big simplification for my code...

many greetings,
jan
 
There is no beard big enough to make me comfortable enough with my masculinity to wear pink. Tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic