呵呵,大斑竹睡觉了,偶来回答2吧
import java.net.*;
class  Getip{
public static void main(String  args[])  {
try{
   String s=InetAddress.getLocalHost().getHostAddress();
   System.out.println(s);
}
catch(Exception e){}
  }