IP2Location总是打印“无效的数据库路径”。 - 如何调用他们的数据库文件?

发布于 2025-01-21 17:26:52 字数 3545 浏览 2 评论 0原文

为了从IP地址获得2封国家信件,建议我使用此bin数据库 https://lite.ip2location.com/database-ip-country-region-city

但是,无论我将其数据库文件放置在何处,我总是会收到此错误消息:

Invalid Database Path.

我猜该行在此行中

oIP2Location.IPDatabasePath = "IP2LOCATION-LITE-DB1.BIN"

:一些代码。 如何正确链接到bin文件的路径?

    Private Sub Query(ByVal strIPAddress As String)
    Dim oIPResult As New IP2Location.IPResult
    Dim oIP2Location As New IP2Location.Component
    Try
        If strIPAddress <> "" Then
            oIP2Location.IPDatabasePath = "IP2LOCATION-LITE-DB1.BIN" ' only IPv4

            oIPResult = oIP2Location.IPQuery(strIPAddress)
            Select Case oIPResult.Status
                Case "OK"
                    Me.txtIPResult.Text += "IP Address: " & oIPResult.IPAddress & vbNewLine
                    Me.txtIPResult.Text += "City: " & oIPResult.City & vbNewLine
                    Me.txtIPResult.Text += "Country Code: " & oIPResult.CountryShort & vbNewLine
                    Me.txtIPResult.Text += "Country Name: " & oIPResult.CountryLong & vbNewLine
                    Me.txtIPResult.Text += "Postal Code: " & oIPResult.ZipCode & vbNewLine
                    Me.txtIPResult.Text += "Domain Name: " & oIPResult.DomainName & vbNewLine
                    Me.txtIPResult.Text += "ISP Name: " & oIPResult.InternetServiceProvider & vbNewLine
                    Me.txtIPResult.Text += "Latitude: " & oIPResult.Latitude & vbNewLine
                    Me.txtIPResult.Text += "Longitude: " & oIPResult.Longitude & vbNewLine
                    Me.txtIPResult.Text += "Region: " & oIPResult.Region & vbNewLine
                    Me.txtIPResult.Text += "Time Zone: " & oIPResult.TimeZone & vbNewLine
                    Me.txtIPResult.Text += "Net Speed: " & oIPResult.NetSpeed & vbNewLine
                    Me.txtIPResult.Text += "IDD Code: " & oIPResult.IDDCode & vbNewLine
                    Me.txtIPResult.Text += "Area Code: " & oIPResult.AreaCode & vbNewLine
                    Me.txtIPResult.Text += "Weather Station Code: " & oIPResult.WeatherStationCode & vbNewLine
                    Me.txtIPResult.Text += "Weather Station Name: " & oIPResult.WeatherStationName & vbNewLine
                    Me.txtIPResult.Text += "MCC: " & oIPResult.MCC & vbNewLine
                    Me.txtIPResult.Text += "MNC: " & oIPResult.MNC & vbNewLine
                    Me.txtIPResult.Text += "Mobile Brand: " & oIPResult.MobileBrand & vbNewLine
                    Me.txtIPResult.Text += "Elevation: " & oIPResult.Elevation & vbNewLine
                    Me.txtIPResult.Text += "Usage Type: " & oIPResult.UsageType & vbNewLine
                Case "EMPTY_IP_ADDRESS"
                    Response.Write("IP Address cannot be blank.")
                Case "INVALID_IP_ADDRESS"
                    Response.Write("Invalid IP Address.")
                Case "MISSING_FILE"
                    Response.Write("Invalid Database Path.")
            End Select
        Else
            Response.Write("IP Address cannot be blank.")
        End If
    Catch ex As Exception
        Response.Write(ex.Message)
    Finally
        oIPResult = Nothing
        oIP2Location = Nothing
    End Try
End Sub

In order to get 2 letters of country from IP Address, I was advised to use this bin database https://lite.ip2location.com/database-ip-country-region-city

But wherever I place their database file, I always get this error message:

Invalid Database Path.

I guess the error lies in this line:

oIP2Location.IPDatabasePath = "IP2LOCATION-LITE-DB1.BIN"

Here's some of the Code. How to correctly link to the path of the BIN file?

    Private Sub Query(ByVal strIPAddress As String)
    Dim oIPResult As New IP2Location.IPResult
    Dim oIP2Location As New IP2Location.Component
    Try
        If strIPAddress <> "" Then
            oIP2Location.IPDatabasePath = "IP2LOCATION-LITE-DB1.BIN" ' only IPv4

            oIPResult = oIP2Location.IPQuery(strIPAddress)
            Select Case oIPResult.Status
                Case "OK"
                    Me.txtIPResult.Text += "IP Address: " & oIPResult.IPAddress & vbNewLine
                    Me.txtIPResult.Text += "City: " & oIPResult.City & vbNewLine
                    Me.txtIPResult.Text += "Country Code: " & oIPResult.CountryShort & vbNewLine
                    Me.txtIPResult.Text += "Country Name: " & oIPResult.CountryLong & vbNewLine
                    Me.txtIPResult.Text += "Postal Code: " & oIPResult.ZipCode & vbNewLine
                    Me.txtIPResult.Text += "Domain Name: " & oIPResult.DomainName & vbNewLine
                    Me.txtIPResult.Text += "ISP Name: " & oIPResult.InternetServiceProvider & vbNewLine
                    Me.txtIPResult.Text += "Latitude: " & oIPResult.Latitude & vbNewLine
                    Me.txtIPResult.Text += "Longitude: " & oIPResult.Longitude & vbNewLine
                    Me.txtIPResult.Text += "Region: " & oIPResult.Region & vbNewLine
                    Me.txtIPResult.Text += "Time Zone: " & oIPResult.TimeZone & vbNewLine
                    Me.txtIPResult.Text += "Net Speed: " & oIPResult.NetSpeed & vbNewLine
                    Me.txtIPResult.Text += "IDD Code: " & oIPResult.IDDCode & vbNewLine
                    Me.txtIPResult.Text += "Area Code: " & oIPResult.AreaCode & vbNewLine
                    Me.txtIPResult.Text += "Weather Station Code: " & oIPResult.WeatherStationCode & vbNewLine
                    Me.txtIPResult.Text += "Weather Station Name: " & oIPResult.WeatherStationName & vbNewLine
                    Me.txtIPResult.Text += "MCC: " & oIPResult.MCC & vbNewLine
                    Me.txtIPResult.Text += "MNC: " & oIPResult.MNC & vbNewLine
                    Me.txtIPResult.Text += "Mobile Brand: " & oIPResult.MobileBrand & vbNewLine
                    Me.txtIPResult.Text += "Elevation: " & oIPResult.Elevation & vbNewLine
                    Me.txtIPResult.Text += "Usage Type: " & oIPResult.UsageType & vbNewLine
                Case "EMPTY_IP_ADDRESS"
                    Response.Write("IP Address cannot be blank.")
                Case "INVALID_IP_ADDRESS"
                    Response.Write("Invalid IP Address.")
                Case "MISSING_FILE"
                    Response.Write("Invalid Database Path.")
            End Select
        Else
            Response.Write("IP Address cannot be blank.")
        End If
    Catch ex As Exception
        Response.Write(ex.Message)
    Finally
        oIPResult = Nothing
        oIP2Location = Nothing
    End Try
End Sub

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

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

发布评论

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

评论(1

赤濁 2025-01-28 17:26:52

您有2个选项来指定bin文件的路径。

要么使用BIN文件的完整路径。

oIP2Location.IPDatabasePath = "c:\myfolder\mysubfolder\IP2LOCATION-LITE-DB1.BIN"

或使用网站根文件夹的相对路径并调用Mappath获取完整的路径。下面的示例是bin文件夹中的bin文件。

oIP2Location.IPDatabasePath = Server.MapPath("bin\IP2LOCATION-LITE-DB1.BIN")

You have 2 options for specifying the path to the BIN file.

Either use the full path to the BIN file.

oIP2Location.IPDatabasePath = "c:\myfolder\mysubfolder\IP2LOCATION-LITE-DB1.BIN"

Or use the relative path to the website root folder and call MapPath to get the full path. Below example is for a BIN file inside the bin folder.

oIP2Location.IPDatabasePath = Server.MapPath("bin\IP2LOCATION-LITE-DB1.BIN")
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文