• 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
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

Accessing a Remote machine Using Java

 
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I need to know another machines CPU Utilization,OS specific information using Java.I have 2 information.
1. That machines IP.
2.That machine OS is windows.
Apart from this nothing I know .

Can it be done ? If yes how ? How can know even my own machines CPU Utilization,OS specific information using Java ? If possible please send me some sample code .
Regards,
Ayan
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well you would probably have to write client apps that reside on the other machines, and has a deamon thread running waiting for calls. Then from you app you call the client machines deamon thread requesting that information. Then the client app gets the information and sends it back. Or you client app can be loaded into the RMI Registry on the client machine, which is just like above. Either way there needs to be an application running on the client machine. Since a remote machine cannot get that other information directly.

Mark
 
Ayan Dutta
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have been successful to login to another machine using telnet.I have used
jakarta commons-net-1.4.1.jar to login to another machine. My code is like this...

import org.apache.commons.net.telnet.*;
import java.io.*;

public class Final {

public static void main(String[] args) throws IOException {

TelnetClient telnet = null;
InputStream in = null;
PrintStream out = null;

try {
telnet = new TelnetClient();
telnet.connect("administ", 23);
in = telnet.getInputStream();
out = new PrintStream(telnet.getOutputStream());
System.out.println("Successfully Connected");

executeCommand("administrator", in, out);
executeCommand("\n", in, out);
executeCommand("", in, out);
executeCommand("\n", in, out);

executeCommand("dir", in, out);
executeCommand("\n", in, out);

readOutput(telnet.getInputStream());

} catch (Exception e) {
e.printStackTrace();
} finally {
if (in != null) {
in.close();
}
if (out != null) {
out.close();
}
if (telnet != null) {
telnet.disconnect();
telnet = null;
System.out.println("\nSuccessfully Disconnected");
}
}
}

public static void executeCommand(String command, InputStream in,
PrintStream out) {
for (int i = 0; i < command.length(); i++) {
char c = command.charAt(i);
out.write((int) c);
}
}

public static void readOutput(InputStream in) {
int j = 0;
try {
while (j < 300) {
j++;
System.out.print((char) in.read());
}

} catch (Exception e) {
}
}
}




Upto login and password entry it is working fine.But when I execute the dir command ,the output thai is coming is in a scrambled format.But is coming .How can I format the output ?
Ayan
 
Ranch Hand
Posts: 1170
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is more of a windows question than a Java question.
 
Ranch Hand
Posts: 163
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Ayan Dutta:
Hi,
I need to know another machines CPU Utilization,OS specific information using Java.I have 2 information.
1. That machines IP.
2.That machine OS is windows.
Apart from this nothing I know .

Can it be done ? If yes how ? How can know even my own machines CPU Utilization,OS specific information using Java ? If possible please send me some sample code .
Regards,
Ayan



I think a better solution would be to download and install jvmstat:

http://java.sun.com/performance/jvmstat/

You'll be able to monitor memory and such very nicely with that.
 
Ayan Dutta
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks I have solved the problem.I will send the code very soon.
I want to say something to Mr C Lamont Gilbert ,
As there are rules for asking questions ,then there should be some thought applied before answering any question.If someone goes through my code properly ,the main problem is in formatting the content from an InputStream.
And this is not an windows related question at all.Having no answer is better than having baseless comments.
Regards
Ayan
 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ayan,

I also have a similar requirement for getting CPU Utilization of a machine using its IP Address. As said in your last reply, can you please post the entire code for achieving that requirement on this site or send it to my yahoo id : niksdeshpande@yahoo.com?

Thanks in advance.

Regards,
Shailesh.
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi ayan when i run this code only login id is asked
suddenly it shows Successfully Disconnected.
So please tell me how to proceed its urgent for me.
And one more thing what is "administrator" in this.
suppose my login id and assword is abcdef asdfg resp.

Bhuvnesh
 
Sheriff
Posts: 17125
298
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
@bhuvnesh bansal: Note that the last reply before your post was dated more than seven years ago.
The value "administrator" appears to be the command he is trying to execute. If you want to execute shell commands, check out the java.lang.Runtime and java.lang.Process classes first.
 
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

Ayan Dutta wrote:I have been successful to login to another machine using telnet.


Well, that, to me, is your first mistake.

I'm an old sysadmin, and I would never allow anyone - including me - to use telnet on one of my machines.

So all I can say is that if your solution is based on telnet, it would never get past one of my firewalls - and if it did, I'd resign long before I was fired.

Winston
 
Junilu Lacar
Sheriff
Posts: 17125
298
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ayan is probably not going to see the new activity in this thread... I agree, telnet'ing around is not the right way to do this. At the very least, use secure shell (ssh) if you're going into remote machines.
 
bhuvnesh bansal
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am successfully connected through connect method but when i enter login no forward process is shown...
 
Get out of my mind! Look! A tiny ad!
Garden Master Course kickstarter
https://coderanch.com/t/754577/Garden-Master-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic