专注收集记录技术开发学习笔记、技术难点、解决方案
网站信息搜索 >> 请输入关键词:
您当前的位置: 首页 > Java Web开发

根据ip取得所在城市

发布时间:2010-05-30 22:57:26 文章来源:www.iduyao.cn 采编人员:星星草
根据ip获得所在城市
由于在做一个网站,需要根据客户的ip获得所在城市,并直接显示出来。在网上搜到的除了收费的都是用纯真ip地址库,看了也不是太清楚,请高手们帮忙,还有没有别的方法,或者给个纯真ip地址库的程序!谢谢了!

------解决方案--------------------
全国ip的分配跟手机号码的分配是差不多的,都是根据地区有不同的号段

你需要根据给出的ip去匹配看是那个区域。。
------解决方案--------------------
 这是java的,可以参考。
http://showtime520.iteye.com/blog/340548
------解决方案--------------------

<script type=text/javascript src=http://fw.qq.com/ipaddress></script>
<script type=text/javascript>
document.write(IPData.join(' '));
</script> 

------解决方案--------------------
我这有个接口可以获取到,程序代码也有!
如果你需要可以找我!
------解决方案--------------------
package Test;

import org.apache.axiom.om.OMAbstractFactory;
import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.OMFactory;
import org.apache.axiom.om.OMNamespace;
import org.apache.axiom.soap.SOAP11Constants;
import org.apache.axis2.Constants;
import org.apache.axis2.addressing.EndpointReference;
import org.apache.axis2.client.Options;
import org.apache.axis2.client.ServiceClient;

public class IPtest {

 private static EndpointReference targetRPR =
        new EndpointReference("http://www.webxml.com.cn/WebServices/IpAddressSearchWebService.asmx?wsdl"); //web服务地址

 public void getResult() throws Exception   
    {   
        ServiceClient sender = new ServiceClient();   
        sender.setOptions(buildOptions());   

        OMElement result = sender.sendReceive(buildParam()); 
        System.out.println( result.toString());   
    }   
private OMElement buildParam() {
 OMFactory fac = OMAbstractFactory.getOMFactory();   

        OMNamespace omNs = fac.createOMNamespace("http://WebXml.com.cn/", "");   
        OMElement data = fac.createOMElement("getCountryCityByIp", omNs);    //方法名称
        OMElement inner = fac.createOMElement("theIpAddress", omNs);     //参数名称
        inner.setText("58.195.128.56");                                         //输入进去的参数
        data.addChild(inner);   

        return data;   
}
private Options buildOptions() {
 Options options = new Options();   
        options.setSoapVersionURI(SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI);   
        options.setAction("http://WebXml.com.cn/getCountryCityByIp");   
        options.setTo(targetRPR);     
        options.setTransportInProtocol(Constants.TRANSPORT_HTTP); 

        return options;   
}
/**
 * @param args
 */
public static void main(String[] args) {
IPtest t = new IPtest();
try {
t.getResult();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

}

}
友情提示:
信息收集于互联网,如果您发现错误或造成侵权,请及时通知本站更正或删除,具体联系方式见页面底部联系我们,谢谢。

其他相似内容:

热门推荐: