File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Sockets and Internet Protocols and the fly likes IP C-Class Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Reply Bookmark "IP C-Class" Watch "IP C-Class" New topic
Author

IP C-Class

Doua Beri
Ranch Hand

Joined: Sep 24, 2009
Posts: 60
Hi. I have 2 String vars ip1 and ip2 . How can I compare to see if they are from the same C-class or not. Thanks in advance

This message was edited 1 time. Last update was at by Doua Beri

Rob Spoor
Saloon Keeper

Joined: Oct 27, 2005
Posts: 17259

Two ways (assuming IPv4):
- use substring matching. Cut off the last octet of both IP addresses and then check for equality
- convert to a byte[] using InetAddress, then compare the first three elements of the two arrays


SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
Doua Beri
Ranch Hand

Joined: Sep 24, 2009
Posts: 60
OK. thanks
Rob Spoor
Saloon Keeper

Joined: Oct 27, 2005
Posts: 17259

You're welcome.
 
 
subject: IP C-Class
 
Two Laptop Bag