• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

java networking

 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i have try to get mac address(physical address ) with below code

Inet Address ip=InetAddress.getLocalHost();
NetworkInterface networkInterface= NetworkInterface.getByInetAddress(ip);
byte[] byteNetwork=networkInterface.getHardwareAddress();

but everytime i run program it give different address and when internet connection has lost it give mac address is NULL .I think mac address is physical address so

it should not change, so how can i get mac address(physical address)
 
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

hari shukla wrote:it should not change, so how can i get mac address(physical address)


I'm way out of my depth here, but if it was me, my first thought would be that you're not allowed to get the mac address; and, in good "protection" mode, it doesn't tell you that - it simply returns something you can't use.

However, I've never tried what what you're doing, I'm simply guessing. It's certainly what I'd do if I was the security admin on that machine.

Winston
 
hari vallabh shukla
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can we get mac address(physical address) of local machine through java
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

hari shukla wrote: i have try to get mac address(physical address ) with below code

Inet Address ip=InetAddress.getLocalHost();
NetworkInterface networkInterface= NetworkInterface.getByInetAddress(ip);
byte[] byteNetwork=networkInterface.getHardwareAddress();

but everytime i run program it give different address and when internet connection has lost it give mac address is NULL .I think mac address is physical address so

it should not change, so how can i get mac address(physical address)



It works fine for me. I ran it about twenty times, and I got the same MAC address (for the same NIC) every time.

I was unable to get a null for the MAC address, but I did noticed that when all the NICs were disabled, you get the loopback address as the ip address (which makes sense, as the loopback is the only usable interface). And the loopback interface isn't a hardware NIC, so it doesn't have a MAC address. For the loopback, I noticed that it returned a zero length address as the MAC address.

Henry
 
Henry Wong
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Winston Gutkowski wrote:
I'm way out of my depth here, but if it was me, my first thought would be that you're not allowed to get the mac address; and, in good "protection" mode, it doesn't tell you that - it simply returns something you can't use.

However, I've never tried what what you're doing, I'm simply guessing. It's certainly what I'd do if I was the security admin on that machine.




According to the javadoc for the NetworkInterface class, it is supposed to return null, if the caller doesn't have permission to access the MAC address.

Henry
 
reply
    Bookmark Topic Watch Topic
  • New Topic