[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Stupid Applet question



Chris,

If the applet is a trusted applet here how can you get
name and ip adress:


import java.applet.Applet;
import java.awt.Label;
import java.net.InetAddress;


public class HostInfoApplet extends Applet {
   private Label lhostAddress;
   private Label lhostName;
   private static String hostAddress;
   private static String hostName;


   public void init() {
      setHostInfo();
   }
   public void start() {
      printHostInfo();
      lhostAddress = new Label("HostAddress: " +
getHostAddress());
      add(lhostAddress);
      lhostName = new Label("HostName: " +
getHostName());
      add(lhostName);

   }
   public void stop() {
      remove(lhostAddress);
      remove(lhostName);
   }

   public String getHostAddress() {
      return this.hostAddress;
   }
   public String getHostName() {
      return this.hostName;
   }

   private void setHostInfo()
   {
	 try {
		InetAddress ina = InetAddress.getLocalHost();
		hostAddress = ina.getHostAddress();
		hostName = ina.getHostName();
		ina = null;
	}
	catch(Exception e) {
		e.printStackTrace();
	}
   }

   public void printHostInfo()
   {
	  System.out.println("Host Address: " + hostAddress);
	  System.out.println("Host Name: " + hostName);
   }
}
====== index.html ========
<title>HostInfo Applet</title>
<hr>
<applet code="HostInfoApplet.class" width=300
height=100>
</applet>
<hr>
====== end index.html =====


--- cfowler <cfowler@outpostsentinel.com> wrote:
> In an applet, How can I get the IP Address of my
> server since I'm only
> allowed to connect to that server?
> 
> Thanks,
> Chris
> 
> 
> 


__________________________________________________
Do you Yahoo!?
Yahoo! Web Hosting - Let the expert host your site
http://webhosting.yahoo.com