Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
manucng davangere
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator



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
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64972
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"manu pg", please check your private messages for an important administrative matter.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64972
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
[removed]
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64972
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please check your private messages. Again.
 
Himanshu Kansal
Ranch Hand
Posts: 257
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Maneesh Godbole
Saloon Keeper
Posts: 11070
13
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Rob Spoor
Sheriff
Pie
Posts: 20550
57
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Himanshu Kansal
Ranch Hand
Posts: 257
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 15367
40
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Himanshu Kansal
Ranch Hand
Posts: 257
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 15367
40
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Pie
Posts: 21202
81
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
manucng davangere
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 15367
40
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20550
57
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 11888
203
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Rob Spoor
Sheriff
Pie
Posts: 20550
57
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Pie
Posts: 21202
81
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic