import java.net.*; class test { public static void main(String[] args) { System.out.println((new test()).getAddress()); //在這顯示ip } public String getAddress() { InetAddress localIp; try{ localIp=InetAddress.getLocalHost(); String ip=localIp.getHostAddress(); return ip; }catch(UnknownHostException une) { } return null; } }
沒有留言:
張貼留言