File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes verification of ip-addresses Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "verification of ip-addresses" Watch "verification of ip-addresses" New topic
Author

verification of ip-addresses

Jan Groth
Ranch Hand

Joined: Feb 03, 2004
Posts: 456
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
Ta Ri Ki Sun
Ranch Hand

Joined: Mar 26, 2002
Posts: 442
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

Joined: Feb 03, 2004
Posts: 456
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
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: verification of ip-addresses
 
Similar Threads
InetAddress class
Seems like I can't read from a scoket?
Apache cant be seen on WAN
How to know programmatically whether a machne is in Global/Private network ?
J2se server and J2me client