Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2010-11-27
3
Medium Priority
?
912 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 1000 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 1000 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
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.
Suggested Courses

782 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