日期:2014-05-17  浏览次数:20761 次

根据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