Solved

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

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

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.…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
The viewer will learn how to implement Singleton Design Pattern in Java.
Suggested Courses

627 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