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.
dotnet new console --language VB
dotnet add package Newtonsoft.Json
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
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.
Empower your applications with accurate IP geolocation information now.
Try It for Free