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

44ay_
  • 27
  • 1
  • 5
  • 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"? – Ibrennan208 Jun 29 '22 at 06:33
  • You have to connect to database like using SQLConnection https://learn.microsoft.com/en-us/dotnet/api/system.data.sqlclient.sqlconnection?view=dotnet-plat-ext-6.0 – Markus Meyer Jun 29 '22 at 06:36
  • Does this answer your question? [How do I connect to a SQL database from C#?](https://stackoverflow.com/questions/1345508/how-do-i-connect-to-a-sql-database-from-c) – Ibrennan208 Jun 29 '22 at 06: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: https://fileinfo.com/extension/bin And this: https://en.wikipedia.org/wiki/Binary_file – Ibrennan208 Jun 29 '22 at 06:39
  • The information which is stored in the .bin data should be stored in a database in Microsoft SQL Management Studio. I hope this could answer your question. – 44ay_ Jun 29 '22 at 06:57
  • Does this answer your question? [VS2010 How to include files in project, to copy them to build output directory automatically during build or publish](https://stackoverflow.com/questions/4596508/vs2010-how-to-include-files-in-project-to-copy-them-to-build-output-directory-a) – Nitin Sawant Jun 29 '22 at 07:10
  • If its SQL Server you'll have to restore it on your server and then learn how to connect to a SQL database using C#, which has been linked in several comments. – Ibrennan208 Jun 29 '22 at 07:17
  • 2
    This BIN format is described on the site where you (probably) downloaded it: https://blog.ip2location.com/knowledge-base/what-is-ip2location-bin-data-file/ – Klaus Gütter Jun 29 '22 at 11:02

1 Answers1

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.

Vlam
  • 1,622
  • 1
  • 8
  • 17