Solved

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

Posted on 2010-11-27
3
895 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
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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
spring jars download 1 35
runtime exception 2 41
Why doesn't this text field show up on my Applet frame? 2 19
Java basic valueOf question 1 29
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

809 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