import java.net.InetAddress;
import java.net.UnknownHostException;
public class Test{
public static void main(String args[]) {
try{
System.out.println(InetAddress.getByName("localhost"));
}
catch(UnknownHostException e){
System.out.println("未知的主机名");
}
}
}
import java.net.UnknownHostException;
public class Test{
public static void main(String args[]) {
try{
System.out.println(InetAddress.getByName("localhost"));
}
catch(UnknownHostException e){
System.out.println("未知的主机名");
}
}
}
{
public static Add ina
{
public static void main(Stringp[] args)
{
ina=Add.getByName("你的计算机名");
Systm.out.print("ina.getHostAddress());
}
}
}
import java.net.*;
public class MyIPAddress {
public MyIPAddress() {
}
public static void main(String[] args){
try{
InetAddress ipa = InetAddress.getByName("localhost");
System.out.println("Host name:" + ipa.getHostName());
System.out.println("Host Ip Address"+ ipa.getLocalHost());
System.out.println("Local Host:"+ InetAddress.getLocalHost());
}catch(UnknownHostException e){
System.out.println(e.toString());
}
}
}
import javax.swing.*;
import java.net .*;
//<applet code=test.class width=250 height=150></applet>
public class test extends JApplet
{
InetAddress myComputer;
String ip;
public void init()
{
try
{
myComputer=InetAddress.getLocalHost(); //取得主机位置对象
}
catch (UnknownHostException e)
{}
ip=myComputer.getHostAddress();
System.out.println(ip);
}
};