cxf获取本地IP
来源:互联网 发布:阿里云 深信服 编辑:程序博客网 时间:2024/05/15 04:43
package com.coupon.webservice.impl;
import java.net.InetAddress;
import java.net.NetworkInterface;
import org.apache.cxf.message.Message;
import org.apache.cxf.phase.PhaseInterceptorChain;
import org.apache.cxf.transport.http.AbstractHTTPDestination;
private String getIp() throws SocketException{
Message message = PhaseInterceptorChain.getCurrentMessage();
HttpServletRequest httprequest = (HttpServletRequest)message.get(AbstractHTTPDestination.HTTP_REQUEST);
return httprequest.getRemoteAddr();
}
private 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;
}
}
import java.net.InetAddress;
import java.net.NetworkInterface;
import org.apache.cxf.message.Message;
import org.apache.cxf.phase.PhaseInterceptorChain;
import org.apache.cxf.transport.http.AbstractHTTPDestination;
private String getIp() throws SocketException{
Message message = PhaseInterceptorChain.getCurrentMessage();
HttpServletRequest httprequest = (HttpServletRequest)message.get(AbstractHTTPDestination.HTTP_REQUEST);
return httprequest.getRemoteAddr();
}
private 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;
}
}
- cxf获取本地IP
- cxf获取客户端Ip
- cxf获取客户端Ip
- CXF获取客户端IP
- sqlplus获取本地IP
- 获取本地ip
- DEPHI 获取本地IP
- 获取本地IP
- QT获取本地ip
- 获取本地IP地址
- 获取本地IP
- 获取本地IP
- php 获取本地IP
- 获取本地IP方法
- 获取本地IP地址
- 获取本地IP
- qt获取本地ip
- ioctl获取本地IP
- hadoop-改进的wordcount
- VB.NET机房个人重构版-磨刀篇(一)
- 【转】物联网跟我动手做系列教程—第三篇 实验三如何用arduino+ethernet shield与yeelink结合5分钟实现web远程家电控制(代码已更新)
- MPLS Terminology & Label Operations
- VC 资源和函数调用
- cxf获取本地IP
- Linux 多线程应用中的信号处理
- Unrecognized xbean element mapping: beans in namespace http://xfire.codehaus.org
- [Hadoop] Cloudera Impala:基于Hadoop的实时查询开源项目
- init: cannot execve('/system/bin/drmserver'): Permission denied
- 有符号和无符号数的比较
- php上传apk后自动提取apk包的信息
- Struts2与Axis2整合配置UrlPattern冲突问题
- php.ini的参数设置(定制)