This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Java in General and the fly likes NIC ADDRESS Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "NIC ADDRESS" Watch "NIC ADDRESS" New topic
Author

NIC ADDRESS

Swaminathan Nagarajan
Greenhorn

Joined: Feb 23, 2004
Posts: 1
Hi,
I am trying to get NIC(Network Interface Card) Address using java 2.0. Do u have any idea how to get the NIC address
of an machine.
Thanks,
Swami
Eddie Vanda
Ranch Hand

Joined: Mar 18, 2003
Posts: 281
Maybe you could arrange the execution of the ipconfig dos command and capture its output? When you use "ipconfig /all" it provides the NIC address. When you use "ipconfig /all >x.txt" it puts the output into x.txt which you could read with your java program. Maybe someone else has some idea on how to run a dos program from java???


The nice thing about Standards is that there are so many to choose from!
Tony Morris
Ranch Hand

Joined: Sep 24, 2003
Posts: 1608
@see java.net.NetworkInterface
Why are some developers so intent on running a system command to achieve something ? *especially* when the core API provides the desired behaviour.
*shakes head in disbelief*


Tony Morris
Java Q&A (FAQ, Trivia)
Eddie Vanda
Ranch Hand

Joined: Mar 18, 2003
Posts: 281
Not sure whether to hang my head in shame or not, but I do not see any thing about NIC addresses in that class, only IP details. But I am certainly not an expert in that area. My impression is that java isolates you from all that low level stuff.
Robert Paris
Ranch Hand

Joined: Jul 28, 2002
Posts: 585
Well, here's some code showing you how to get the NIC cards and some of their info, BUT, I couldn't find out how to get the NIC Cards' physical addresses.

How do I get the physical address? For example, an address like: 00-EE-AA-BB-00-00 (I made it up, but you get the idea). I don't see any place where I can obtain that.
[ February 26, 2004: Message edited by: Robert Paris ]
Robert Paris
Ranch Hand

Joined: Jul 28, 2002
Posts: 585
I've got some code that works on Windows, OS X and Linux, but they're all just parsing "ifconfig" from Runtime.exec(). Is there really no other way to do this? I have written C code on Windows to grab the Mac Address, but MS helpfully made those APIs different on almost every Windows version (i.e. what works on 98 won't on 2000, etc). Further, I'm not sure that Linux or Unix or OS X have system APIs available for that - I think the only way to get a NIC's address on those OS's is from ifconfig.
Is this really true? Is there no other way? Why is it so "ugly" to get that info in Java (or any language apparently)?
Does anyone have code for getting MAC address on Unix, Solaris? How would I know it was Unix? (i.e. what would System.getProperty( "os.name" ) return?)
Tom Blough
Ranch Hand

Joined: Jul 31, 2003
Posts: 263
How about a call to the system ARP server? You'll have to use some native code to get to OSI Layer 2 since Java only deals with layers 3 & 4.
Tom Blough
[ February 26, 2004: Message edited by: Tom Blough ]

Tom Blough<br /> <blockquote><font size="1" face="Verdana, Arial">quote:</font><hr>Cum catapultae proscriptae erunt tum soli proscripti catapultas habebunt.<hr></blockquote>
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: NIC ADDRESS