java - InetAddress.getLocalHost().getHostName() throws UnknownHostException -


i trying host name off server running.

java code:

import java.net.inetaddress;  system.out.println("host name: " + inetaddress.getlocalhost().gethostname()); system.exit(0); 

output:

java.net.unknownhostexception: thinkpad-edge-e430: thinkpad-edge-e430: name or service not known @ java.net.inetaddress.getlocalhost(inetaddress.java:1473) @ mailq.main(mailq.java:45) caused by: java.net.unknownhostexception: thinkpad-edge-e430: name or service not known @ java.net.inet6addressimpl.lookupallhostaddr(native method) @ java.net.inetaddress$1.lookupallhostaddr(inetaddress.java:901) @ java.net.inetaddress.getaddressesfromnameservice(inetaddress.java:1293) @ java.net.inetaddress.getlocalhost(inetaddress.java:1469) ... 1 more 

hosts:

127.0.0.1   localhost #admin.local.com #127.0.1.1  thinkpad-edge-e430 192.168.81.238 admin.local.com # following lines desirable ipv6 capable hosts ::1     ip6-localhost ip6-loopback fe00::0 ip6-localnet ff00::0 ip6-mcastprefix ff02::1 ip6-allnodes ff02::2 ip6-allrouters 

i cant find issue here. can me out?

try this:

import java.net.inetaddress; import java.net.unknownhostexception;  /**  * @author crunchify.com  */  public class crunchifygetiphostname {      public static void main(string[] args) {          inetaddress ip;         string hostname;         try {             ip = inetaddress.getlocalhost();             hostname = ip.gethostname();             system.out.println("your current ip address : " + ip);             system.out.println("your current hostname : " + hostname);          } catch (unknownhostexception e) {              e.printstacktrace();         }     } } 

you test code online on http://www.browxy.com/

i have taken http://crunchify.com/how-to-get-server-ip-address-and-hostname-in-java/


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -