Wednesday, June 3, 2009

Computer Name / Hostname

Hi All,

I have a feeling some times, that I dont have much of Java stuff on my blog. Though this post does not talk much about some Java code, I have at least something.

My computer assembler - Ananth Ram had a problem in wading off a boot virus in one of his client's system. During the same time I called him and he wanted some help. Nevertheless the help that I gave him did not work, I learnt some things and I finally recalled that I had studied them somewhere.

He wanted the Computer Name, a.k.a the hostname of that infected virus's machine. So I was googling the net finding ways to find the hostname without logging into the machine.

I found out these things:

1. The easiest way:

If one can login into a system running XP, we have the easiest way. Right click on My Computer and go to properties. In one of the tabs there, you would find the Computer name.

2. The Network way:

Give the following command in your cmd prompt - ipconfig /all

3. The DOS way:

You had the following command - NET Status

4. The Linux ways:

4.a Using an UNIX command:

Give the following command on your konsole - hostname

4.b The Lenny way:

Open the following command in your konsole - gnome-system-monitor
The first line in the opened window is the hostname / computername

5. The Java / Programmatic way:

Copy paste the below bolded code in a file called ComputerName.java and run the application.

package test;

import java.net.* ;

public class ComputerName {

public static void main ( String[] args ) {


try {
String computerName = InetAddress.getLocalHost( ).getHostName ();
System.out.println ( "Computer Name: " + computerName ) ;
}
catch ( Exception e ) {
System.out.println ( " Cannot get computer name " + e ) ;
}
}
}



Finally before ending, I could recall that I had read the above 5th way's code in Java Complete Reference book written by Herbert Schildt.

Try out which ever way you like to. Enjoy!!!!

Thanks,
Ananth Gouri

No comments:

Post a Comment