全国ip的分配跟手机号码的分配是差不多的,都是根据地区有不同的号段你需要根据给出的ip去匹配看是那个区域。。

解决方案 »

  1.   

     这是java的,可以参考。
    http://showtime520.iteye.com/blog/340548
      

  2.   

    这我也知道,关键是不知道怎么用java代码实现
      

  3.   


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

  4.   


    <script type=text/javascript src=http://fw.qq.com/ipaddress></script>
    <script type=text/javascript>
    document.write(IPData[2] + IPData[3]);
    </script> 
      

  5.   

    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();
    } }}
      

  6.   

    private static void getData(String querySQL) throws Exception{
            URL url = new URL("http://api.liqwei.com/location/");
            // 打开连接,此处只是创建一个实例,并没有真正的连接
    HttpURLConnection httpCon = (HttpURLConnection) url.openConnection();
    httpCon.setDoOutput(true);//打开写入属性
    httpCon.setRequestMethod("GET");//设置提交方法
            String params = "ip=" +rs.getString("ip_address"); 
    // 此处调用getOutputStream会隐含的进行connect操作,所以不用在上面显示调用connect()
    httpCon.getOutputStream().write(params.getBytes());
    httpCon.getOutputStream().flush();
    httpCon.getOutputStream().close();
    //如果inputStream读操作在outputStream的写操作之前,会抛java.net.ProtocolException
    //将内存缓冲区中封装好的完整的HTTP请求电文发送到服务端。 
    InputStream inputStream = httpCon.getInputStream();
    InputStreamReader inputReader = new InputStreamReader(inputStream,"gbk");
    BufferedReader bufferReader = new BufferedReader(inputReader);
            String inputLine = null;  
    StringBuffer sb = new StringBuffer();
    while ((inputLine = bufferReader.readLine()) != null) {   
    sb.append(inputLine);
    }   
    bufferReader.close();  
    inputReader.close();
    inputStream.close();
    System.out.println(sb.toString());
    }
    你在运行这个方法前,去看下http://api.liqwei.com/location/,这个里面有很多接口,供你使用,你找到IP的后,你就知道,该怎么获取城市了。上面打印的sb就是查询到的数据。
      

  7.   

    直接利用接口调用,现在淘宝的,新浪的接口调用都很准确。
    比如 http://ip.taobao.com/service/getIpInfo.php?ip=211.138.125.150 你可以去看下他们的官网api