Solved

Getting IP and MAC Addresses on a LAN via Custom Application?

Posted on 2010-11-27
3
889 Views
Last Modified: 2012-05-10
Hi:

[1] I would like to know if via Java Code preferably or by Perl whether or not I can find out all the IP and MAC addresses currently connected to my LAN?  The LAN would be connected to the Internet via a Linux Box with two Nics - one for the internet and the other for the LAN switch.  My custom application would be running on this same box, so if there is a service or other application that I would be able to query in order to get this information and make things easier, let me know.

[2] If the above is possible, a brief explanation and a supplied example of the key parts of the code would be appreciated.

Note Requirements: Reporting of information to be quick; not eat up a lot of bandwidth; if using SNMP would help, then please incorporate in the solution given.

Thanks
0
Comment
Question by:Hope4U
3 Comments
 
LVL 16

Accepted Solution

by:
Blaz earned 250 total points
Comment Utility
You can never know for sure the machines attached to a LAN. A machine could theoretically be passively listening to the network traffic and never send any packets - therefore it would be invisible to all other devices on LAN.

Also network switches filter traffic that is sent to each switch port - all clients do not get all the traffic.

Note that you can only see the correct MAC address of the client only if it is in the same subnet (no routers in between).

Depending on your needs however there are methods that can get you close.
1. If you have DHCP server and dynamic allocation of IP addresses on the network then you could know which machines are connected to the LAN from the DHCP server (although a machine could bypass this if it wanted by setting a fixed IP).

2. If you are interested only in the machines that are communicating to the internet (through your box) then you could analyze network traffic and get IPs and MACs from there

3. If you are interested only in the machines that are CURRENTLY (=in the last couple of minutes) communicating to the internet (through your box) then you could look at current ARP table (ARP table stores which MAC address belongs to which IP address). You can look at the current ARP table with command:
/sbin/arp -n
0
 

Author Comment

by:Hope4U
Comment Utility
Hi Blaz:

Could you please give me an example of the key parts of the code (preferably in Java) OR some helpful URLs for doing solutions: 2 (Analyzing network traffic) and 3 (using the Linux command '/sbin/arp -n' ) .

Thank You
0
 
LVL 28

Assisted Solution

by:FishMonger
FishMonger earned 250 total points
Comment Utility
Why not use nmap to scan your network?  If you want, you could use Java or Perl as a wrapper that executes and parses the nmap scans.

http://nmap.org/

There are Perl modules available on CPAN to interface with nmap.
http://search.cpan.org/search?query=nmap&mode=all
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

I have seen several blogs and forum entries elsewhere state that because NTFS volumes do not support linux ownership or permissions, they cannot be used for anonymous ftp upload through the vsftpd program.   IT can be done and here's how to get i…
Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
This video teaches viewers about errors in exception handling.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now