how to take computer name in linux

Reply

Join Date: Apr 2007
Posts: 34
Reputation: onsir is an unknown quantity at this point 
Solved Threads: 1
onsir onsir is offline Offline
Light Poster

how to take computer name in linux

 
0
  #1
Jan 25th, 2008
how to take computer name in linux
I had tried this code in Windows Xp, it's Ok. but while i run in linux i got error
"Cannot get computer name java.net.UnknownHostException: comcentos: comcentos"

i'm using Centos 5.

i have edit in file etc/sysconfig/network
NETWORKING=yes
NETWORKING_IPV6=yes
HOSTNAME=comcentos
  1. package myPackage;
  2. import java.io.* ;
  3. import java.net.* ;
  4.  
  5. public class ComputerName {
  6.  
  7. public static void main ( String[] args ) {
  8.  
  9. //To get the computer name
  10. try {
  11. String computerName = InetAddress.getLocalHost( ).getHostName ();
  12. System.out.println ( "Computer Name: " + computerName ) ;
  13. }
  14. catch ( Exception e ) {
  15. System.out.println ( " Cannot get computer name " + e ) ;
  16. }
  17. }
  18. }

thanks all for your help
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 15
Reputation: mrynit is an unknown quantity at this point 
Solved Threads: 0
mrynit's Avatar
mrynit mrynit is offline Offline
Newbie Poster

Re: how to take computer name in linux

 
0
  #2
Jan 26th, 2008
it works fine for me using Ubuntu 7.10 and java version 1.5.0_14. check your java config?
Last edited by mrynit; Jan 26th, 2008 at 1:36 am.
Reply With Quote Quick reply to this message  
Join Date: Apr 2007
Posts: 34
Reputation: onsir is an unknown quantity at this point 
Solved Threads: 1
onsir onsir is offline Offline
Light Poster

Re: how to take computer name in linux

 
0
  #3
Jan 27th, 2008
What is i must config java. I'm using java jdk_1.6 update 3 with netbeans 6.0
while i intsall java i used jdk-6u3-nb_0-linux.sh
thanks
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Java Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC