aspose file tools*
The moose likes Java in General and the fly likes Get Serial number of exernal hard disk/Thumbdrive using java code &work for both linux and windows Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Get Serial number of exernal hard disk/Thumbdrive using java code &work for both linux and windows" Watch "Get Serial number of exernal hard disk/Thumbdrive using java code &work for both linux and windows" New topic
Author

Get Serial number of exernal hard disk/Thumbdrive using java code &work for both linux and windows

manucng davangere
Greenhorn

Joined: Aug 10, 2009
Posts: 12



Hi guys,

I am new tio java networking concepts.Please tel me how to get Serial number of exernal hard disk/Thumbdrive using java code.and it should work for both linux and windows(platform independent).please send any Documentaton or example if You knw.

manu

regards,
manu
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60041
    
  65

"manu pg", please check your private messages for an important administrative matter.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60041
    
  65

Please do not ask for answer to be emailed to you. Please read this for more information.

Also, please use real words when posting to the forums. Abbreviations such as "knw" in place of "know" only serve to make your posts more difficult to read and less likely to generate useful responses.

Please read this for more information.

thanks,
bear
JavaRanch sheriff
manucng davangere
Greenhorn

Joined: Aug 10, 2009
Posts: 12
[removed]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60041
    
  65

Please check your private messages. Again.
Himanshu Kansal
Ranch Hand

Joined: Jul 05, 2009
Posts: 257
Alright, just in the interest of the community or atleast mine, do we have an answer to that?
Moreover is it ethical to do so if possible?


Experience and talent are independent of age
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 9990
    
    7

Himanshu Kansal wrote:Alright, just in the interest of the community or atleast mine, do we have an answer to that?
Moreover is it ethical to do so if possible?


I am not really sure what you are trying to say here. Your first statement gives me the impression that "ok. enough of this rules and regulations. just give out the answer.". I am sure you did not mean it that way, but that's how it came off to me.
I also, am not sure what do you mean by ethical. Could you please rephrase?

There could be various reasons why nobody has posted the answer. For me, I know how to do it, but only on windows and the OP wants a cross platform solution.


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19538
    
  16

You will have to go native, but you can simply provide two implementing libraries; one DLL ("javaranch.dll") for Windows and one shared library ("libjavaranch.so") for Linux.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Himanshu Kansal
Ranch Hand

Joined: Jul 05, 2009
Posts: 257
We all are here to learn and help learn. The one who started the thread was evident to not reply and I wished the interest of the community be maintained. It's not only the one asking question gets the solution and off he goes. Many others get to learn, surfing through.

That's all what I meant. No offences.

"Ethical" has been used as in "ethical hacking". Is getting SID ok?

Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 13867
    
  10

Why assume that manucng wants this because he is "hacking"?

Maybe he wants to secure his application in a way, so that it only runs on the computer for which his client bought a license. The program would check, by looking at some unique serial number of the harddisk or motherboard, if it's really running on the computer that the license was bought for.

Note that security measures like that are not infallible; someone who really wants to break the security could decompile or reverse engineer the application and try to remove the security check.

Anyway, this kind of thing is not possible in pure Java. You'd need a platform-specific native library for different platforms on which you want to support such a feature.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Himanshu Kansal
Ranch Hand

Joined: Jul 05, 2009
Posts: 257
Jesper Young wrote: Why assume that manucng wants this because he is "hacking"?

Atleast I am not assuming this, other I don't know of. I use the term to explain the meaning of the word "ethical", would have been better to 'copy paste' from a dictionary I guess.

If such a mechanism is used for securing, re-installation is the easiest way to break it. Usually a registry key would be setup to prevent re-installation. Also such a mechanism would not be format safe.

Anyhow, I think we are deviating from the original question. If I may know, how can we do this?

Regards
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 13867
    
  10

The original question has already been answered:
Anyway, this kind of thing is not possible in pure Java. You'd need a platform-specific native library for different platforms on which you want to support such a feature.
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18101
    
  39

I am not even convinced that this can even be done reliably with all OSes -- regardless of whether Java is being used. The serial number is something that is just a sticker with certain harddrives.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
manucng davangere
Greenhorn

Joined: Aug 10, 2009
Posts: 12
i am not willing to hack any os or application.i want to secure my application such that no one can steel my application using their thumdrive or EXTERNAL hard disk.i don want to read serial number of cd/internal hard disk.i can get code for windows os.but i want code such that it has to work for both linux and windows.
manucng davangere
Greenhorn

Joined: Aug 10, 2009
Posts: 12
Rob Prime wrote:You will have to go native, but you can simply provide two implementing libraries; one DLL ("javaranch.dll") for Windows and one shared library ("libjavaranch.so") for Linux.



means? whether i have to create mfc/win32 dll using visual studio?.if so i can create dll for windows os.i don know how to create for linux?.will the same dll work for linux?.
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 13867
    
  10

Yes, you will have to create a DLL for Windows (and you don't need MFC for that, MFC is for programming GUIs, and the DLL doesn't need to do anything with a GUI).

No, the same DLL will not work on Linux. You will need to write a shared library for Linux (which will be named "libsomething.so"). You'll have to learn how to program in C for Linux to do that.

If you also want to do it for Apple computers running Mac OS X, it's different again.

You'll need to use JNI to call those native libraries from Java.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19538
    
  16

For Windows, you can use Visual Studio, but not with MFC as Jesper said. If you don't have Visual Studio you can also use MinGW in combination with gcc. You can also use Delphi with the help of this page.

For Linux, gcc is usually the way to go. No idea what Mac OS X uses.
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11277
    
  59

manucng davangere wrote:i want to secure my application such that no one can steel my application using their thumdrive or EXTERNAL hard disk.i don want to read serial number of cd/internal hard disk.i can get code for windows os.but i want code such that it has to work for both linux and windows.

I'm confused by your stated aims versus your way of attempting to go about it. The only way I can reconcile this is if you were distributing your application on a thumbdrive, and wanted to confirm that the thumbdrive is present on it.

Personally, I would prefer to look for the network adapter's MAC address (using java.net.NetworkInterface#getHardwareAddress()). That should be unique per computer, and is unlikely to change very often.


The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19538
    
  16

It should be unique, but most (all?) operating systems allow you to change it. Granted, there aren't many people who do so, but it's still a possibility.
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18101
    
  39


I agree with Andrew here. If you need a value that is unique to a machine, the mac address is the way to go. These values are actually assigned by the vendors to make sure that they are unique -- as duplicate values will cause it to not work on a switch/hub.

And yes, they can be reassigned... and in the case of a virtual environment, I did this all the time, after copying a VM. You can also automatically get a new mac, when multiple NICs are bonded. etc. The point is... this is still probably your best bet at locking the application to a machine. Sure, a mac address can be reassigned, but if the user has that skill, he can decompile your program too, and even if the mac is reassigned, it won't work if it is on the same LAN as the other machine.

Henry
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Get Serial number of exernal hard disk/Thumbdrive using java code &work for both linux and windows
 
Similar Threads
Difference between UBUNTU bootable USB drive and UBUNTU installation on USB Drive
exernal file
how to get hard disk serial number using java
harddisk serial number