2010-12-04 9 views
1

クラシックASP 3.0を使用して訪問国の情報を取得する必要があります。下記のコードを使用していますが、国名の代わりにXXが返されます。これに関する提案/助言。クラシックASP 3.0を使用して訪問者の国情報を取得

<% 
     URL = "http://api.hostip.info/country.php?ip=" & Request.ServerVariables("REMOTE_ADDR") 
     Set conn = Server.CreateObject("MSXML2.ServerXMLHTTP") 
     conn.open "GET", URL, False, "", "" 
     conn.send 
     UserCountry = conn.ResponseText   
     Response.Write(UserCountry) 

%> 

私は上記のコードを含むビューのページも設定しました。

http://www.datingmaze.co.uk/rac.asp

私はhttp://api.hostip.info/country.php?ip=12.215.42.19をしようとした場合、それは私に正しい出力が得られますが、私が試した場合http://api.hostip.info/country.php?ip=119.152.136.247は私が正しいIPアドレスを提供する、すなわちXXが間違った出力を提供します。

ありがとうございます。

答えて

2

これにはGeoIPを使用できます。

彼らはあなたが使用できる無料のCOM APIを持っている:

<% 
if Request.Form("values") = "Test Values" then 
hostname = "www.yahoo.com" 
else 
    hostname = Request.Form("hostname") 
end if 

if Request.Form("submit") = "Submit" then 

    set geoip = Server.CreateObject("GeoIPCOMEx.GeoIPEx") 

    geoip.set_db_path("C:\Program Files\GeoIP\") 
geoip.find_by_name(hostname) 
city = geoip.city 

    Response.Write("<table cellpadding=2 border=1><tr><th colspan=2>Results</th></tr>") 
    Response.Write("<tr><td>Hostname</td><td>" + hostname + "</td></tr>") 
    Response.Write("<tr><td>GeoIP City Value</td><td>" + city + "</td></tr>") 
    Response.Write("</table>") 
end if 
%> 

http://www.maxmind.com/app/com

http://www.maxmind.com/GeoIP-COM-1.3.zip

彼らのCOM APIには、次のことを公開します。

Methods: 
bool set_db_path(string path) (must be set before any other operations, true if all dbs found) 
bool find_by_addr(string ipvalue) (return true if address found, sets all properties) 
bool find_by_name(string dns_name) (-"-) 

あなたのデータ検索後に受け取る:

Properties: 
country_code (2 chars; "LN" if non-routed addr, "LH" if localhost) 
country_code3 (3 chars) 
country_name ("Local Area Network" if non-routed addr,"Localhost" if localhost) 
region (2 chars, state abbrev for US/Canada, FIPS 10-4 region code for others) 
city 
postal_code (max 6 chars, US and Canada only) 
latitude (real number) 
longitude (real number) 
dma_code (integer) 
area_code (integer) 

したがって、find_by_nameを使用する代わりに、find_by_addrを使用します。どちらがIPv4アドレスに基づいて国を検索するか。

これは、リモートのサードパーティプロバイダに頼っていると危険である可能性があるため、これは優れたソリューションです。

http://www.maxmind.com/app/geolitecountry

:自分のサイトには、

あなたがここに自分のIP /カントリーデータベースの無料版をダウンロードすることができますなど、高負荷の下でも、下がるかもしれません

関連する問題