To detect if an IP address is a VPN using IP2Location.io in VB.NET, you can use the IP2Location.io API to retrieve geolocation and related data.
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("proxy") IsNot Nothing Then
If results("proxy")("is_vpn") Then
Console.WriteLine("The IP " & ip & " is a VPN.")
Else
Console.WriteLine("The IP " & ip & " is NOT a VPN.")
End If
Else
Throw New Exception("ERROR: The is_vpn field requires a paid subscription to the Security plan.")
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 check if the specified IP address is a VPN. 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