使用经典 ASP 3.0 获取访问者国家/地区信息

发布于 2024-10-06 05:07:26 字数 919 浏览 0 评论 0原文

我需要使用经典 asp 3.0 获取访问者国家/地区信息,我使用下面的代码,但它返回我 XX 而不是国家/地区名称。对此有任何建议/帮助。

<%
        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

如果我尝试< a href="http://api.hostip.info/country.php?ip=12.215.42.19" rel="nofollow">http://api.hostip.info/country.php?ip=12.215.42.19< /a> 它给了我正确的输出,但如果我尝试 http://api. hostip.info/country.php?ip=119.152.136.247 给我错误的输出,即 XX,尽管我提供了正确的 IP 地址。

提前致谢。

I need to get visitors country information using classic asp 3.0, i'm using below code but it returns me XX instead of country name. any suggestions/help on this.

<%
        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)

%>

i have also setup a page for view which contains the above code.

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

If i try http://api.hostip.info/country.php?ip=12.215.42.19 it gives me correct output, but if i tried http://api.hostip.info/country.php?ip=119.152.136.247 gives me wrong output i.e. XX although i provided the correct IP address.

thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

情定在深秋 2024-10-13 05:07:26

您可以使用 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< /a>

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

他们的 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_addr,而不是使用 find_by_name。这将根据 IPv4 地址查找国家/地区。

这是一个更好的解决方案,因为依赖远程第三方提供商可能存在风险。他们的网站可能会崩溃、负载过重等。

您可以在此处下载其 IP/国家/地区数据库的免费版本:

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

You can use GeoIP for this.

They have a free COM API which you can use:

<%
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

Their COM API exposes the following:

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) (-"-)

The data that you would receive after lookup:

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)

So instead of the using find_by_name, you would use find_by_addr. Which would lookup the country based on an IPv4-address.

This is a better solution since relying on remote 3rd party providers can be risky. Their site might go down, be under heavy load, etc.

You can download the free version of their IP/Country database here:

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文