您现在的位置: 爱51代码网 >> 范文 >> 文章正文
Java通过IP地址获取用户所在地源代码
                  :host   => 'geoip.maxmind.com',
                      :path   => '/e',
                      :query  => URI.encode_www_form(:l => options[:license],
                                                     :i => options[:ip]))

response = Net::HTTP.get_response(uri)

unless response.is_a?(Net::HTTPSuccess)
  abort "Request failed with status #{response.code}"
end

omni = Hash[fields.zip(response.body.encode('utf-8', 'iso-8859-1').parse_csv)]

if omni[:error]
  abort "MaxMind returned an error code for the request: #{omni[:error]}"
else
  puts
  puts "MaxMind Omni data for #{options[:ip]}";
  puts
  omni.each { |key, val| printf "  %-20s  %s\n", key, val }
  puts
end
最后再来个Perl版本吧:


[python] view plaincopyprint?
01.#!/usr/bin/env perl  
02. 
03.use strict; 
04.use warnings; 
05. 
06.use Encode qw( decode ); 
07.use Getopt::Long; 
08.use LWP::UserAgent; 
09.use Text::CSV_XS; 
10.use URI; 
11.use URI::QueryParam; 
12. 
13.my @fields = qw( 
14.    country_code 
15.    country_name 
16.    region_code 
17.    region_name 
18.    city_name 
19.    latitude 
20.    longitude 
21.    metro_code 
22.    area_code 
23.    time_zone 
24.    continent_code 
25.    postal_code 
26.    isp_name 
27.    organization_name 
28.    domain 
29.    as_number 
30.    netspeed 
31.    user_type 
32.    accuracy_radius 
33.    country_confidence 
34.    city_confidence 
35.    region_confidence 
36.    postal_confidence 
37.    error 
38.); 
39. 
40.my $license_key = 'YOUR_LICENSE_KEY'; 
41.my $ip_address  = '24.24.24.24'; 

上一页  [1] [2] [3] [4] [5] [6] [7] [8] [9] [10]  ... 下一页  >> 

  • 上一篇文章:

  • 下一篇文章: 没有了
  • 最新文章 热点文章 相关文章
    android手机无法与eclipse或电脑
    C/C++洗牌算法源代码
    servlet技术实现用户名唯一的验证
    E-business suite system servic
    ZOJ 3700 Ever Dream 文章中单词
    TortoiseGit和msysGit安装及使用
    asp中有一段javascipt的网页鼠标
    sharepoint 2010 获取用户信息Us
    设计包含max函数的队列
    随机从数组中取出指定的不重复的
    ZOJ 3700 Ever Dream 文章中单词
    TortoiseGit和msysGit安装及使用
    sharepoint 2010 获取用户信息Us
    mysql主从同步延迟方案解决的学习
    生日旅行总结
    中小板生日快乐随感
    送生日快乐桑葚乳酪小蛋糕
    写给女儿的生日快乐
    总分公司财务核算
    恢复使用繁体字可行性研究报告
    android编译时出现'Unab
    Android 仿 WP7 布局
    windows下搭建SVN服务器及配
    javascript中级联下拉列表
    jsp页面中表单action=“”为
    当session失效后重新登录成功
    jsp页面中点击导航字,右边输
    java线程同步的方法
    java数据连接池的工作机制是
    forward和redirect的区别
     



    设为首页 | 加入收藏 | 网站地图 | 友情链接 |