如何获得内网IP

mmrwbb 2009-10-25 08:02:03
如何获得内网IP?并将它最后一位截取出来 比如 内网IP 10.0.0.101 把101取出来
...全文
226 15 打赏 收藏 转发到动态 举报
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
zl3450341 2009-10-26
  • 打赏
  • 举报
回复
String str=request.getRemoteAddr();
string laststr=str.substring(str.lastIndexOf(".")+1);
shang_zchao 2009-10-26
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 closewbq 的回复:]
Java codepublicstaticvoid main(String[] args) {
Enumeration<NetworkInterface> netInterfaces=null;try {
netInterfaces= NetworkInterface.getNetworkInterfaces();while (netInterfaces.hasMoreElements()) {
NetworkInterface ni= netInterfaces.nextElement();
System.out.println("DisplayName:"+ ni.getDisplayName());
System.out.println("Name:"+ ni.getName());
Enumeration<InetAddress> ips= ni.getInetAddresses();while (ips.hasMoreElements()) {
System.out.println("IP:"+ ips.nextElement().getHostAddress());
}
}
}catch (Exception e) {
e.printStackTrace();
}
}
[/Quote]学习
a043028448 2009-10-25
  • 打赏
  • 举报
回复
goole之
铁匠梁 2009-10-25
  • 打赏
  • 举报
回复
没有考虑使用代理的情况
liuhua_sun 2009-10-25
  • 打赏
  • 举报
回复
嗯!都解决了啊!顶啊!
miaosha2009 2009-10-25
  • 打赏
  • 举报
回复
百度上有很多咯
BearRui 2009-10-25
  • 打赏
  • 举报
回复
String str=request.getRemoteAddr();
string laststr=str.substring(str.lastIndexOf(".")+1);
mmrwbb 2009-10-25
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 findee 的回复:]
String str=request.getRemoteAddr(); 
string laststr=str.substring(str.lastIndexOf("."));
[/Quote]


6楼 截出来是".101"啊
小一郎 2009-10-25
  • 打赏
  • 举报
回复
用request对象里的getRemoteAddr()方法
findee 2009-10-25
  • 打赏
  • 举报
回复
String str=request.getRemoteAddr();
string laststr=str.substring(str.lastIndexOf("."));
rookie001 2009-10-25
  • 打赏
  • 举报
回复
4L,学习啦
closewbq 2009-10-25
  • 打赏
  • 举报
回复

public static void main(String[] args) {
Enumeration<NetworkInterface> netInterfaces = null;
try {
netInterfaces = NetworkInterface.getNetworkInterfaces();
while (netInterfaces.hasMoreElements()) {
NetworkInterface ni = netInterfaces.nextElement();
System.out.println("DisplayName:" + ni.getDisplayName());
System.out.println("Name:" + ni.getName());
Enumeration<InetAddress> ips = ni.getInetAddresses();
while (ips.hasMoreElements()) {
System.out.println("IP:"
+ ips.nextElement().getHostAddress());
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
mmrwbb 2009-10-25
  • 打赏
  • 举报
回复
访问页面机器的IP。。
liuhua_sun 2009-10-25
  • 打赏
  • 举报
回复
你只要获取自己机子上的还是整个内网的都需要获取啊?
434gfhghghg444545 2009-10-25
  • 打赏
  • 举报
回复
在servlet里面有个方法可以获取客户端的ip,然后你用substring截取

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧