Reputation: 1
I have a Java server where I need to check if an IP is local or public when I get a connection. I can detect it when its my own local IP but I'm having some trouble with other local IPs. Does Java give us a way to do it? I haven't found it, so probably we should convert IP to numbers and check if is in the local IP range. How can I get this range?
Upvotes: 0
Views: 2754
Reputation:
The private IP ranges are:
10.0.0.0/8 (from 10.0.0.0 to 10.255.255.255) [ Named as Class A Private Network ]
172.16.0.0/12 (from 172.16.0.0 to 172.31.255.255) [ Named as Class B Private Network ]
192.168.0.0/16 (from 192.168.0.0 to 192.168.255.255) [ Named as Class C Private Network ]
Upvotes: 2
Reputation: 11117
An IP address within one of three ranges are used within local networks only (behind routers and firewalls) and considered as private IP address ranges.
I don't think Java provide such a way to tell if an IP address is private or public. I think you have to write your own function.
Upvotes: 0
Reputation: 1151
You need to elaborate your question. From my understanding you want to check whether the IP lies inside 192.x.x.x or outside the range. If that is the case just a string or integer comparision will solve your question.
Upvotes: 0