㈠ java怎么获取当前电脑的内网ip

public void PingAll() throws Exception{
//首先得到本机的IP,得到网段
InetAddress host = InetAddress.getLocalHost();
String hostAddress = host.getHostAddress();
int k=0;
k=hostAddress.lastIndexOf(".");
String ss = hostAddress.substring(0,k+1);
for(int i=1;i <=255;i++){ //对所有局域网Ip
String iip=ss+i;
Ping(iip);
}

㈡ 局域网中的电脑如何用java代码取得出口IP

public class GetRealIp {
public static void main(String[] args) throws SocketException {
System.out.println(GetRealIp.getRealIp());
}
public static String getRealIp() throws SocketException {
String localip = null;// 本地IP,如果没有配置外网IP则返回它
String netip = null;// 外网IP
Enumeration<NetworkInterface> netInterfaces =
NetworkInterface.getNetworkInterfaces();
InetAddress ip = null;
boolean finded = false;// 是否找到外网IP
while (netInterfaces.hasMoreElements() && !finded) {
NetworkInterface ni = netInterfaces.nextElement();
Enumeration<InetAddress> address = ni.getInetAddresses();
while (address.hasMoreElements()) {
ip = address.nextElement();
if (!ip.isSiteLocalAddress()
&& !ip.isLoopbackAddress()
&& ip.getHostAddress().indexOf(":") == -1) {// 外网IP
netip = ip.getHostAddress();
finded = true;
break;
} else if (ip.isSiteLocalAddress()
&& !ip.isLoopbackAddress()
&& ip.getHostAddress().indexOf(":") == -1) {// 内网IP
localip = ip.getHostAddress();
}
}
}
if (netip != null && !"".equals(netip)) {
return netip;
} else {
return localip;
}
}
}
自己写了一个帮你实现,希望对你有帮助

㈢ 如何在局域网部署我的java项目,就是让局域网的用户,通过打我的IP直接访问我的javaweb项目

先查自己的IP,可以点开始运行然后输入CMD,跳出DOS窗口后,输入“ipconfig”跳出来的选项中有个ip address后面的就是你的内网地址,比如我是:192.168.0.87
然后把项目放到tomcat的webapps下,启动,别人就可以通过
http://192.168.0.87:8080/项目名/index.jsp类似这样的就可以访问了