-1

I am working on an application, which gets the public IP address of the user, looks up in a database for the location of that IP address, gets the Latitude an Longitude and finally displays the time of sunrise and sunset at that place.

To make step two work, I need to implement a database file in my project. I have downloaded the database file (.bin - format) already but I couldn't make it work to connect my program with the downloaded database file.

Download of database file below:

enter image description here

How can I solve this?

Cheers!

8
  • 4
    What type of database? .bin doesn't specify much. Is it just a data dump you downloaded from some other source? Is it a SQL database or MySQL database file? Text file used as a "Database"? Commented Jun 29, 2022 at 6:33
  • You have to connect to database like using SQLConnection learn.microsoft.com/en-us/dotnet/api/… Commented Jun 29, 2022 at 6:36
  • Does this answer your question? How do I connect to a SQL database from C#? Commented Jun 29, 2022 at 6:37
  • Guessing it is SQLite by the term LITE in the filename. That being said, it's just a guess, and it still isn't clear. Perhaps the location you got it from is able to tell you more about it? Check out this: fileinfo.com/extension/bin And this: en.wikipedia.org/wiki/Binary_file Commented Jun 29, 2022 at 6:39
  • 2
    This BIN format is described on the site where you (probably) downloaded it: blog.ip2location.com/knowledge-base/… Commented Jun 29, 2022 at 11:02

1 Answer 1

1

You can use the IP2Location NuGet package https://www.nuget.org/packages/IP2Location.IPGeolocation/ and call it like below:

Dim oIPResult As New IP2Location.IPResult
Dim oIP2Location As New IP2Location.Component
Try
    Dim strIPAddress = "8.8.8.8"
    If strIPAddress.Trim <> "" Then
        oIP2Location.Open("C:\myfolder\IP-COUNTRY-REGION-CITY-LATITUDE-LONGITUDE-ZIPCODE-TIMEZONE-ISP-DOMAIN-NETSPEED-AREACODE-WEATHER-MOBILE-ELEVATION-USAGETYPE-ADDRESSTYPE-CATEGORY.BIN", True)
        oIPResult = oIP2Location.IPQuery(strIPAddress)
        Select Case oIPResult.Status
            Case "OK"
                Console.WriteLine("IP Address: " & oIPResult.IPAddress)
                Console.WriteLine("City: " & oIPResult.City)
                Console.WriteLine("Country Code: " & oIPResult.CountryShort)
                Console.WriteLine("Country Name: " & oIPResult.CountryLong)
                Console.WriteLine("Postal Code: " & oIPResult.ZipCode)
                Console.WriteLine("Domain Name: " & oIPResult.DomainName)
                Console.WriteLine("ISP Name: " & oIPResult.InternetServiceProvider)
                Console.WriteLine("Latitude: " & oIPResult.Latitude)
                Console.WriteLine("Longitude: " & oIPResult.Longitude)
                Console.WriteLine("Region: " & oIPResult.Region)
                Console.WriteLine("TimeZone: " & oIPResult.TimeZone)
                Console.WriteLine("NetSpeed: " & oIPResult.NetSpeed)
                Console.WriteLine("IDD Code: " & oIPResult.IDDCode)
                Console.WriteLine("Area Code: " & oIPResult.AreaCode)
                Console.WriteLine("Weather Station Code: " & oIPResult.WeatherStationCode)
                Console.WriteLine("Weather Station Name: " & oIPResult.WeatherStationName)
                Console.WriteLine("MCC: " & oIPResult.MCC)
                Console.WriteLine("MNC: " & oIPResult.MNC)
                Console.WriteLine("Mobile Brand: " & oIPResult.MobileBrand)
                Console.WriteLine("Elevation: " & oIPResult.Elevation)
                Console.WriteLine("Usage Type: " & oIPResult.UsageType)
                Console.WriteLine("Address Type: " & oIPResult.AddressType)
                Console.WriteLine("Category: " & oIPResult.Category)
            Case "EMPTY_IP_ADDRESS"
                Console.WriteLine("IP Address cannot be blank.")
            Case "INVALID_IP_ADDRESS"
                Console.WriteLine("Invalid IP Address.")
            Case "MISSING_FILE"
                Console.WriteLine("Invalid Database Path.")
        End Select
    Else
        Console.WriteLine("IP Address cannot be blank.")
    End If
Catch ex As Exception
    Console.WriteLine(ex.Message)
Finally
    oIP2Location.Close()
    oIPResult = Nothing
    oIP2Location = Nothing
End Try

Example code came from https://github.com/ip2location/ip2location-dotnet.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.