get host name that run applet

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • teenIce
    New Member
    • Aug 2007
    • 36

    get host name that run applet

    Hi all,

    I want to know if there are any way to get host name that run an applet.

    e.g : If I run from another computer, it gives the computer name or web name.
  • madhoriya22
    Contributor
    • Jul 2007
    • 251

    #2
    Originally posted by teenIce
    Hi all,

    I want to know if there are any way to get host name that run an applet.

    e.g : If I run from another computer, it gives the computer name or web name.
    Hi,
    I think this will be helpful for u...
    Code:
     
    System.out.println(System.getProperty ("user.name"));

    Comment

    • Nepomuk
      Recognized Expert Specialist
      • Aug 2007
      • 3111

      #3
      Originally posted by madhoriya22
      Code:
       
      System.out.println(System.getProperty ("user.name"));
      That will just give you the username of that computer. I don't think, you can get the Systems name by using System.getPrope rty(...), as the following code should display all possibilities, which (at least on my computer) do not include the Systems name.
      [CODE=java]
      if (args == null || args.length == 0)
      {
      java.util.Enume ration e = System.getPrope rties().propert yNames();
      while (e.hasMoreEleme nts()) {
      String key = (String)e.nextE lement();
      System.out.prin tln(key +"\t : \t"+ System.getPrope rty(key));
      }
      }
      else
      {
      for (int n = 0; n < args.length; ++ n)
      {
      if (args[n] != null && args[n].length() > 0)
      {
      String p = System.getPrope rty(args[n]);
      if (p != null)
      System.out.prin tln(p);
      }
      }
      }
      [/CODE]If you want the actual computers name, try this:
      [CODE=java]
      try {
      java.net.InetAd dress i = java.net.InetAd dress.getLocalH ost();
      System.out.prin tln(i); // name and IP address
      System.out.prin tln(i.getHostNa me()); // name
      System.out.prin tln(i.getHostAd dress()); // IP address only
      }
      catch(Exception e){e.printStack Trace();}
      [/CODE]Source: http://www.rgagnon.com/javadetails/java-0390.html

      Comment

      • teenIce
        New Member
        • Aug 2007
        • 36

        #4
        Originally posted by nepomuk
        That will just give you the username of that computer. I don't think, you can get the Systems name by using System.getPrope rty(...), as the following code should display all possibilities, which (at least on my computer) do not include the Systems name.

        [CODE=java]
        try {
        java.net.InetAd dress i = java.net.InetAd dress.getLocalH ost();
        System.out.prin tln(i); // name and IP address
        System.out.prin tln(i.getHostNa me()); // name
        System.out.prin tln(i.getHostAd dress()); // IP address only
        }
        catch(Exception e){e.printStack Trace();}
        [/CODE]
        thanks...
        i try your code and it works.. :)

        Comment

        Working...