Loading blog entries.. loading


Blogs which referenced tag: [Google]

 


IP Address to Geolocation

 
Written by Wayne Ye  Thursday, December 30, 2010

Background


Few months ago I found an interesting website: http://ipinfodb.com/, it provided API which could "translate" any IP Address into a geography location including City/Region/Country as well as latitude/longitude and time zone information, to invoke its API, a registered API key is required (which is free). Since beforehand I stored visitor's IP Addresses into my own database, I decided to utilize InfoDB API to store visitor's GEO locations.

Just few days ago, I casually emitted an idea: summarize those GEO location records and display them on Google Map, hum, it is feasible:)

So, the process is: Track visitor's IP addresses -> "Translate" them to Geography location -> Show them on Google Map!

(PS, I've been used Google Analytics for my Geek Place - http://WayneYe.com for more than two years, it is no double extremely powerful, and it already contains a feature "Map Overlay", however, due to privacy policy, Google Analytics does NOT display visitor's IP address, see http://www.google.com/support/analytics/bin/answer.py?hl=en&answer=86214).

Implementation


The first task I need to do is track visitor's IP Address, most of the time, user visits a website in browser submits an HTTP GET request (an HTTP data package) based on Transmission Control Protocol (most of the time) , browser passed the ball to DNS server and DNS server delivered the request to the designation - the web host server, during the process, the original Http request was possibly transferred through a number of routers/proxies and many other stuff, the request's header information might have been updated: Via (Standard HTTP request header) or X-Forwarded-For (non-standard header but widely used), could be the original ISP's information/IP Address OR possibly one of the proxy's IP Address.

So, usually the server received the request and saw Via/X-Forwarded-For header information, it got to know visitor's IP address (NOT all the time, some times ISP's IP address), in ASP.NET, it is simply to call Request.UserHostAddress, however, we can never simply trust this because of two major reasons:

  1. Malicious application can forge HTTP request with modified X-Forwareded-To header (for example: X-Forwarded-To: dangerous code), if you are unlucky to trust it and have it inserted into Database, then SQL Injection hole will be utilized by Malicious application.

  2. Not all the visitors are human-been, part of them could be search engine spiders, I must distinguish human visitors and spiders, otherwise for example, I will be happy to see a lot of "visitors" came from "Mountain View, CA" ^_^.


For #1: I use regular expression to validate the string I got from Request.UserHostAddress:
public static Boolean IsValidIP(string ip)
{
if (System.Text.RegularExpressions.Regex.IsMatch(ip, "[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}"))
{
string[] ips = ip.Split('.');
if (ips.Length == 4 || ips.Length == 6)
{
if (System.Int32.Parse(ips[0]) < 256 && System.Int32.Parse(ips[1]) < 256
& System.Int32.Parse(ips[2]) < 256 & System.Int32.Parse(ips[3]) < 256)
return true;
else
return false;
}
else
return false;
}
else
return false;
}

If the result is "0.0.0.0", I will


View Post»



Permalink:http://wayneye.com/Blog/IPAddress-To-Geolocation
Tag:

谷歌的愚人节礼物:)

 
Written by Wayne Ye  Tuesday, April 1, 2008

今天从达人和菜头那里看到谷歌“发布"了新产品:谷歌人肉搜索, 呵呵:
眼前一亮,脑海里浮现的是某个或某些谷歌员工得意的坏笑。。。
摘抄一些:

谷歌人肉搜索引擎有哪些特点?

  • 规模最大:第一期工程拟招募人肉搜索志愿者2500万名,完成后将成为亚太地区最大的人肉搜索引擎。
  • 创新最多:256项专利技术,1024篇相关论文,4096次用户调研,65536轮预览版测试。
  • 领域最全:搜索范围涵盖娱乐、影视、体育、社会、名人、百姓、历史、地理、物种、太空等领域。
  • 速度最快:平均查询响应时间32秒。
  • 挖掘最深:曾在预览版测试中,用时128秒,成功定位了中国大陆生产的第一只自动冲水马桶。

人肉搜索志愿者管理专员

  • 博士以上学历
  • 管理学、传播学或相关专业毕业
  • 掌握五种以上方言
  • 有八卦主义精神和凡事不着调作风者优先
NBNB。。。


View Post»



Permalink:http://wayneye.com/ViewBlog.aspx?BlogID=11
Tag: