| 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
|
 |
Rob Spoor
Saloon Keeper
Joined: Oct 27, 2005
Posts: 18365
|
|
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: 18365
|
|
|
You're welcome.
|
 |
 |
|
|
subject: IP C-Class
|
|
|