How can I determine the usage type of an IP address in VB.NET?

To determine the usage type of an IP address using IP2Location.io in VB.NET, you can use the IP2Location.io API to retrieve geolocation and related data. The usage type field specifies how the IP is being used. For usage types supported, please see API documentation for more info.

  1. We'll assume that you have already installed VB.NET and we won't cover that here. You will also need a paid subscription to the Starter plan or higher. Subscribe now!
  2. Using Visual Studio, create a new Console App for VB.NET. Or, in the command line, run the below command inside an empty folder to create the project.
    Bash
    
    dotnet new console --language VB
    			
  3. Next, install the Newtonsoft.Json package using Visual Studio. Or, in the command line, run the below command inside the project folder.
    Bash
    
    dotnet add package Newtonsoft.Json
    			
  4. Edit the Program.vb file and replace the code with the below codes.
    VB.NET
    
    Imports System
    Imports Newtonsoft.Json
    Imports Newtonsoft.Json.Linq
    Imports System.Net
    Imports System.Net.Http
    
    Module Program
        Sub Main()
            Dim client As New HttpClient()
            Dim ip = "8.8.8.8"
            Dim key = "YOUR_API_KEY"
            Try
                Dim response As HttpResponseMessage = client.GetAsync("https://api.ip2location.io/?key=" & key & "&ip=" & ip & "&format=json").Result
                If response.StatusCode = HttpStatusCode.OK Then
                    Dim rawjson As String = response.Content.ReadAsStringAsync().Result
                    Dim results As JObject = JsonConvert.DeserializeObject(Of JObject)(rawjson)
                    If results IsNot Nothing Then
                        If results("usage_type") IsNot Nothing Then
                            Console.WriteLine("The usage type for IP " & ip & " is " & results("usage_type").ToString & ".")
                        Else
                            Throw New Exception("ERROR: The usage_type field requires a paid subscription to the Starter plan or higher.")
                        End If
                    Else
                        Throw New Exception("ERROR: Invalid JSON in response.")
                    End If
                ElseIf response.StatusCode = HttpStatusCode.Unauthorized OrElse response.StatusCode = HttpStatusCode.BadRequest Then
                    Dim rawjson As String = response.Content.ReadAsStringAsync().Result
                    If rawjson.Contains("error_message") Then
                        Dim results As JObject = JsonConvert.DeserializeObject(Of JObject)(rawjson)
                        Throw New Exception("ERROR: " & results("error")("error_message").ToString & ".")
                    End If
                    Throw New Exception(rawjson)
                End If
            Catch ex As HttpRequestException
                Throw New Exception(ex.Message)
            End Try
        End Sub
    End Module
    			
  5. In the command line, run the below command.
    Bash
    
    dotnet run
    			

This script will output the usage type of specified IP address. Make sure to replace 8.8.8.8 with the IP address you want and replace YOUR_API_KEY to your own API key.

Other Languages

Unlock Location Insights For Free

Empower your applications with accurate IP geolocation information now.

Try It for Free