MAC Address is a Unique identification of a Device. Computer, Mobile, Tablet, PC all have a Unique MAC Address. If you want to know about MAC Address here is some, MAC on Wiki. MAC Address is generally 48 bits long eg, 00:ff:a3:f0:76:ae
Here we are going to discuss about How to get that address by using supplied IP Address over the network.
Here is the Java Code
GetMACAddress.java
E:\>javac GetMACAddress.java
E:\>java GetMACAddress 192.168.174.94
0:21:97:8f:1b:a7:
E:\>
This is How you can get a MAC address from any machines from your Network/LAN.
Here we are going to discuss about How to get that address by using supplied IP Address over the network.
Here is the Java Code
GetMACAddress.java
import java.net.Inet4Address;
import java.net.InetAddress;
import java.util.Arrays;
import jpcap.*;
import jpcap.packet.*;
public class GetMACAddress{
public static byte[] arp(InetAddress ip) throws java.io.IOException{
//find network interface
NetworkInterface[] devices=JpcapCaptor.getDeviceList();
NetworkInterface device=null;
loop: for(NetworkInterface d:devices){
for(NetworkInterfaceAddress addr:d.addresses){
if(!(addr.address instanceof Inet4Address)) continue;
byte[] bip=ip.getAddress();
byte[] subnet=addr.subnet.getAddress();
byte[] bif=addr.address.getAddress();
for(int i=0;i<4;i++){
bip[i]=(byte)(bip[i]&subnet[i]);
bif[i]=(byte)(bif[i]&subnet[i]);
}
if(Arrays.equals(bip,bif)){
device=d;
break loop;
}
}
}
if(device==null)
throw new IllegalArgumentException(ip+" is not a local address");
//open Jpcap
JpcapCaptor captor=JpcapCaptor.openDevice(device,2000,false,3000);
captor.setFilter("arp",true);
JpcapSender sender=captor.getJpcapSenderInstance();
InetAddress srcip=null;
for(NetworkInterfaceAddress addr:device.addresses)
if(addr.address instanceof Inet4Address){
srcip=addr.address;
break;
}
byte[] broadcast=new byte[]{(byte)255,(byte)255,(byte)255,(byte)255,(byte)255,(byte)255};
ARPPacket arp=new ARPPacket();
arp.hardtype=ARPPacket.HARDTYPE_ETHER;
arp.prototype=ARPPacket.PROTOTYPE_IP;
arp.operation=ARPPacket.ARP_REQUEST;
arp.hlen=6;
arp.plen=4;
arp.sender_hardaddr=device.mac_address;
arp.sender_protoaddr=srcip.getAddress();
arp.target_hardaddr=broadcast;
arp.target_protoaddr=ip.getAddress();
EthernetPacket ether=new EthernetPacket();
ether.frametype=EthernetPacket.ETHERTYPE_ARP;
ether.src_mac=device.mac_address;
ether.dst_mac=broadcast;
arp.datalink=ether;
sender.sendPacket(arp);
while(true){
ARPPacket p=(ARPPacket)captor.getPacket();
if(p==null){
throw new IllegalArgumentException(ip+" is not a local address");
}
if(Arrays.equals(p.target_protoaddr,srcip.getAddress())){
return p.sender_hardaddr;
}
}
}
public static void main(String[] args) throws Exception{
if(args.length<1){
System.out.println("Usage: java GetMACAddress <ip address>");
}else{
byte[] mac=GetMACAddress.arp(InetAddress.getByName(args[0]));
for (byte b : mac)
System.out.print(Integer.toHexString(b&0xff) + ":");
System.out.println();
System.exit(0);
}
}
}
To run this you need to get a library called WinPCap from winpcap.org for Windows or LibPCap for Linux. And more over you need to get a Java Library JPCap from Click Here .
If you have both these Library installed on your system then you can compile and run.
E:\>javac GetMACAddress.java
E:\>java GetMACAddress 192.168.174.94
0:21:97:8f:1b:a7:
E:\>
This is How you can get a MAC address from any machines from your Network/LAN.
I love this!! Definitely will be keeping this idea in mind!
ReplyDeleteDOT NET Training in Chennai
Dot Net Training in Velachery
Dot Net Training in Adyar
Html5 Training in Chennai
Html5 Courses in Chennai
Dot Net Training in OMR
Dot Net Training in Porur
Great Article
DeleteAndroid Final Year Project Ideas for Computer Science
FInal Year Project Centers in Chennai
JavaScript Training in Chennai
Java Training in Chennai
Thank you for sharing such kind of precious information with us.It really useful for many of them like me.
ReplyDeleteSoftware Testing Training in Chennai
Software testing training in T Nagar
JAVA Training in Chennai
Python Training in Chennai
Hadoop Training in Chennai
Selenium Training in Chennai
Software Testing Training in Chennai
Software testing Training in Velachery
This is really a valuable post... The info shared is helpful and valuable. Thank you for sharing.
ReplyDeleteaviation training in Chennai
air hostess academy in Chennai
Airline Courses in Chennai
Ground staff training in Chennai
Aviation Academy in Chennai
air hostess training in Chennai
airport management courses in Chennai
ground staff training in Chennai
This was an awesome blog. The way the author has delivered the content is really simple and easy to understand. Waiting for more updates.
ReplyDeleteGerman Classes in Mulund
German Classes in Mulund West
French Classes in Mulund West
French Language Classes in Mulund
Spoken English Class in Chennai
Spoken English in Chennai
IELTS Coaching Centre in Chennai
English Speaking Course in Mumbai
IELTS Coaching in Mumbai
ReplyDeleteThanks to the admin you have spend a lot for this blog I gained some useful info for you. Keep doing.
microsoft dynamics crm training institutes in chennai
microsoft dynamics training
CCNA Training in Chennai
Salesforce Training in Chennai
gst classes in chennai
microsoft crm training
web designing training in chennai
Tally Course in Chennai
This article is a very interesting and brief explanation about this topic. I eagerly waiting for your next post...
ReplyDeleteSpark Training in Chennai
Spark Training Academy
Oracle Training in Chennai
Excel Training in Chennai
Oracle DBA Training in Chennai
Embedded System Course Chennai
Tableau Training in Chennai
Power BI Training in Chennai
Social Media Marketing Courses in Chennai
english to bengali typing
ReplyDeleteimo for pc
ReplyDeleteimo for pc
ReplyDeleteThe article is so informative. This is more helpful for our
ReplyDeleteBest online software testing training course institute in chennai with placement
Best selenium testing online course training in chennai
Learn best software testing online certification course class in chennai with placement
Thanks for sharing.
Thanks for sharing an informative blog keep rocking bring more details.I like the helpful info you provide in your articles. I’ll bookmark your weblog and check again here regularly. I am quite sure I will learn much new stuff right here! Good luck for the next!
ReplyDeletemobile application development training online
mobile app development course
mobile application development course
learn mobile application development
mobile app development training
app development training
mobile application development training
mobile app development course online
online mobile application development
The article is so informative. This is more helpful for our
ReplyDeletesoftware testing training and placement
Best selenium testing online course training in chennai
Best online software testing training course institute in chennai with placement
Magento 2 Developer course training institute in chennai
Thanks for sharing.
thanks for your information really good and very nice web design company in velachery
ReplyDeleteAwesome blog with lots of information. It is really helpful for all.
ReplyDeleteAngularJS Training in Chennai
AngularJS course in Chennai
Angular 6 Training in Chennai
ReactJS Training in Chennai
PHP Training in Chennai
Web Designing course in Chennai
Tally course in Chennai
AngularJS Training in Velachery
AngularJS Training in T Nagar
AngularJS Training in Vadapalani
Great Article. Thank you for sharing! Really an awesome post for every one.
ReplyDeleteProject Centers in Chennai
Java Training in Chennai
Final Year Project Domains for IT
Java Training in Chennai
Have a nice blog
ReplyDeleteThank for sharing Information
php online training in chennai
php programming center in chennai
php class in chennnai
php certification course
php developer training institution chennai
php training in chennnai
php mysql course in chennai
php institute in chennnai
php course in chennnai
php training with placement in chennnai
php developer course
Great work!
ReplyDeleteNIce Blog
appium online training
appium training centres in chennai
best appium training institute in chennnai
apppium course
mobile appium in chennnai
mobile training in chennnai
appium training institute in chennnai
ReplyDeleteYou write this post very carefully I think, which is easily understand to me. Not only this, other post is also good. As a newbie this info is really helpful for me. Thanks to you.
seo training in chennai
seo training classes
seo training course
seo training institute in chennai
seo training institutes
seo course in chennai
seo courses in chennai
seo institute in chennai
seo institutes in chennai
seo training institute
seo classes in chennai
seo training center in chennai
seo courses
seo training
seo course
ReplyDeleteThis content of information has
helped me a lot. It is very well explained and easy to understand.
tally training
Tally Training in Chennai
Tally ERP 9 Training
Tally Course
tally classes
Tally institute in Chennai
Tally Training institute in Chennai
Tally course in Chennai
This post gives a piece of excellent information. Keep sharing this blog.
ReplyDeleteSpoken English Classes in Bangalore
Spoken English Classes in Chennai
English Speaking Course in Bangalore
Best Spoken English Classes in Bangalore
Spoken English in Bangalore
English Speaking Classes in Bangalore
AWS Training in Bangalore
Data Science Courses in Bangalore
DOT NET Training in Bangalore
DevOps Training in Bangalore
nice blog..valuable information....thanks for sharing...
ReplyDeleteC C++ Training in Chennai
C Training in Chennai
C++ Training in Chennai
C C++ training in anna nagar
C C++ training in velachery
javascript training in chennai
core java training in chennai
Html5 Training in Chennai
DOT NET Training in Chennai
QTP Training in Chennai
ReplyDeleteReally awesome blog. Your blog is really useful for me. Thanks for sharing this informative blog.
Software Testing Training in Chennai
Software Testing Training in Bangalore
Software Testing Course in Coimbatore
Software Testing Training in Madurai
Software Testing Training Institute in Bangalore
Software Testing Course in Bangalore
Testing Course in Bangalore
Ethical hacking course in bangalore
I really enjoyed this article. I need more information to learn so kindly update it.
ReplyDeleteSalesforce Training in Chennai
salesforce training in bangalore
Salesforce Course in bangalore
best salesforce training in bangalore
salesforce institute in bangalore
salesforce developer training in bangalore
Big Data Course in Coimbatore
Python Training in Bangalore
salesforce training in marathahalli
salesforce institutes in marathahalli
You are providing a post is very useful for develop my knowledge and I learn more info from your blog.
ReplyDeleteDigital Marketing Course In Kolkata
Web Design Course In Kolkata
SEO Course In Kolkata
Way cool! lap Some very valid points! I appreciate you penning this write-up plus the rest of the website is really good.
ReplyDeleteHats off to the writer of this blog. The content seems spectacular and I am sure that no reader would skip your post. Web Designing Course Training in Chennai | Web Designing Course Training in annanagar | Web Designing Course Training in omr | Web Designing Course Training in porur | Web Designing Course Training in tambaram | Web Designing Course Training in velachery
ReplyDeleteHello! I just now would like to supply a massive thumbs up for any wonderful information you could have here within this post. We are coming back to your blog post for further soon. good luck
ReplyDeleteAi & Artificial Intelligence Course in Chennai
PHP Training in Chennai
Ethical Hacking Course in Chennai Blue Prism Training in Chennai
UiPath Training in Chennai
ReplyDeleteThanks of sharing this post…Python is the fastest growing language that helps to get your dream job in a developing area. It says every fundamental in a programming, so if you want to become an expertise in python get some training
Dot Net Training in Chennai | Dot Net Training in anna nagar | Dot Net Training in omr | Dot Net Training in porur | Dot Net Training in tambaram | Dot Net Training in velachery
valuable blog,Informative content...thanks for sharing, Waiting for the next update…
ReplyDeleteStudy Abroad Consultants in Kerala
study abroad consultants in thrissur
Study Abroad Consultants in Calicut
abroad job consultancy in coimbatore
abroad job consultancy in calicut
abroad job recruitment agencies in calicut
study abroad
study in poland
study in europe
education in germany
It is really a very informative post for all those budding entreprenuers planning to take advantage of post for business expansions. You always share such a wonderful articlewhich helps us to gain knowledge .Thanks for sharing such a wonderful article, It will be deinitely helpful and fruitful article.
ReplyDeleteCyber Security Training Course in Chennai | Certification | Cyber Security Online Training Course | Ethical Hacking Training Course in Chennai | Certification | Ethical Hacking Online Training Course | CCNA Training Course in Chennai | Certification | CCNA Online Training Course | RPA Robotic Process Automation Training Course in Chennai | Certification | RPA Training Course Chennai | SEO Training in Chennai | Certification | SEO Online Training Course
Salesforce CRM software will help companies have a brief overview about how their competitors in the similar niche are performing and thereby helping them in developing a solution that would help in efficient management. Salesforce interview questions and answers
ReplyDeleteThis is an excellent blog. Keep sharing the blog.
ReplyDeletehow to pass ielts
ethical hacking course requirements
stress interview questions and answers
core java for selenium
ethical hacking technical interview questions
Your blog is really awesome, it helps to gain more related information.
ReplyDeletewhat is the latest version of php
how to do digital marketing business
innovative digital marketing ideas
big data use cases in manufacturing
salesforce communities
android interview questions for experienced
This is the best post and Keep doing it. Thank you for your valuable efforts...!
ReplyDeleteContent Writing Online Course
Content Writing Training in Chennai
Google Analytics Training in Chennai
Google Analytics Online Training
I was really impressed to see this blog, it was very interesting and it is very useful for all.
ReplyDeletedifference between ai and machine learning
what is react js
amazon products and services
angularjs web development
aws interview questions and answers
devops interview questions and answers
Đại lý vé máy bay Aivivu, tham khảo:
ReplyDeletekinh nghiệm mua vé máy bay đi Mỹ giá rẻ
có vé máy bay từ mỹ về việt nam không
các đường bay từ canada về việt nam
vé máy bay từ hàn quốc về việt nam
I recently visited your blog and this is very useful for me. Thank you for your excellent post...
ReplyDeleteSharePoint Training in Chennai
SharePoint Course in Chennai
PLC Training in Chennai
HR Course in Chennai
Wow! Excellent blog and I really impressed. Keep doing...
ReplyDeleteUi Ux Design Course in Chennai
Ui Ux Course in Chennai
UiPath Online Training
UiPath Training in Chennai
UiPath Training in Bangalore
great writing.Thank you for your valuable post
ReplyDeletePython Training in chennai | Python Classes in Chennai