aspose file tools*
The moose likes Java in General and the fly likes Are there any jar to check whether two ip address is in same network segment Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Are there any jar to check whether two ip address is in same network segment" Watch "Are there any jar to check whether two ip address is in same network segment" New topic
Author

Are there any jar to check whether two ip address is in same network segment

ken jun
Ranch Hand

Joined: Apr 23, 2010
Posts: 46
"IP_A" and its prefix length of subnet mask is known , and there is a "IP_B" , I want to check whether "IP_A" is in the same netwoek segment with "IP_B", is there any jar JAVA has provided?

If there isn't any jar could finish the job.I have to finish by myself.

My way is like this. First make a binary notation according to the prefix length called "subnet" and then use the "subnet" to do AND operation with the "IP_A" ,then get the "network number" , do the same thing using "IP_B" and "subnet" and get another network number(network number2).
Finally compare the "network number" and the "network number2" to see whether they're the same.

If I merely know the prefix length of subnet mask , how can I get the subnet mask in binary or demical notation?
Thanks a lot!
jun
Karthik Shiraly
Ranch Hand

Joined: Apr 04, 2009
Posts: 475
    
    3
Try Apache Commons Net library's SubnetUtils and SubnetInfo.isInRange()
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36475
    
  16
Not a "beginning" question. Moving.
ken jun
Ranch Hand

Joined: Apr 23, 2010
Posts: 46
Karthik Shiraly wrote:Try Apache Commons Net library's SubnetUtils and SubnetInfo.isInRange()


Thanks a lot I will try it after class.... going to have class

Could you give me some tips helping me finish this?
" If I merely know the prefix length of subnet mask , how can I get the subnet mask in binary or demical notation? "
ken jun
Ranch Hand

Joined: Apr 23, 2010
Posts: 46
Campbell Ritchie wrote:Not a "beginning" question. Moving.


ah...I am sorry , how careless I was.. anyway thanks
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36475
    
  16
No problem ; many people do that. Apology accepted.
ken jun
Ranch Hand

Joined: Apr 23, 2010
Posts: 46
Campbell Ritchie wrote:No problem ; many people do that. Apology accepted.


you are so nice .
By the way Could you give me some tips helping me finish this?
" If I merely know the prefix length of subnet mask , how can I get the subnet mask in binary or demical notation? "
ken jun
Ranch Hand

Joined: Apr 23, 2010
Posts: 46
ken jun wrote:
Campbell Ritchie wrote:No problem ; many people do that. Apology accepted.


you are so nice .
By the way Could you give me some tips helping me finish this?
" If I merely know the prefix length of subnet mask , how can I get the subnet mask in binary or demical notation? "


how foolish I was ,the jar SubnetUtils has a constainer that using CIDR, it means I can just know the ip and the prefix.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Are there any jar to check whether two ip address is in same network segment
 
Similar Threads
RedHat Ethernet adapter problem
Java & Windows (7): Reliably getting IPv4 netmask?
Accessing the Subnet Mask
Network Interface Detection issue with jdk1.6
API For Finding Subnet and Ip addresses in JAVA