Solved

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

Posted on 2010-11-27
3
896 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 16

Accepted Solution

by:
Blaz earned 250 total points
ID: 34222414
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
ID: 34224036
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
ID: 34225942
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

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
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.

696 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