axis 获取客户端ip信息
需要jar包:axis.jar. 下载上传文件并改名:axis.jar
package com.myland.jp.itfc.webservice.client.getipaddress;
import java.util.Vector;
import javax.xml.namespace.QName;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
/**
* @create 2015年3月25日
*
* 获取客户端ip信息
*
*/
public class GetIpAddressClient {
private static final Logger log = LogManager.getLogger(GetIpAddressClient.class);
/**
* webservice接口地址
*/
private static String SERVER_URL = "http://webservice.webxml.com.cn/WebServices/IpAddressSearchWebService.asmx";
/**
* 调用的方法名
*/
private static String SERVER_METHOD = "getCountryCityByIp";
private static String SERVER_OPERATION_NAME = "http://WebXml.com.cn/";
/**
* 过输入IP地址查询国家、城市、所有者等信息。
* 没有注明国家的为中国
* @create 2015年3月25日 下午2:53:03
* @param ip
* @return
*/
public static String getCountryCityByIp(String ip) {
String result = null;
Service service = new Service();
Call call;
try {
call = (Call) service.createCall();
call.setTargetEndpointAddress(new java.net.URL(SERVER_URL));
call.setOperationName(new QName(SERVER_OPERATION_NAME, SERVER_METHOD));
call.setReturnType(new QName(SERVER_OPERATION_NAME, SERVER_METHOD), Vector.class);
call.setUseSOAPAction(true);
call.setSOAPActionURI(SERVER_OPERATION_NAME+SERVER_METHOD);
call.addParameter(new QName(SERVER_OPERATION_NAME, "theIpAddress"),
org.apache.axis.encoding.XMLType.XSD_STRING, javax.xml.rpc.ParameterMode.IN);
Vector v = (Vector) call.invoke(new Object[] { ip });
for (int i = 0; i < v.size(); i++) {
System.out.println(v.get(i));
}
} catch(Exception e) {
log.error(e.getMessage(), e);
}
return result;
}
public static void main(String[] args) {
getCountryCityByIp("124.133.246.163");
}
}
控制台打印: 124.133.246.163 山东省济南市 联通