如果您使用的是套接字,您可以这样做socket.getInetAddress().getHostAddress()如果您希望设备获得自己的公共IP地址,可以使用以下方法:URL whatismyip = new URL("http://checkip.amazonaws.com");BufferedReader in = new BufferedReader(new InputStreamReader(whatismyip.openStream()));String ip = in.readLine(); //IP as a stringSystem.out.println(ip);