Question

Let me just start this with what the program is trying to accomplish before I start with my problem. I'm working on a program that checks every 5 to 10 (not implemented yet) seconds to see if you VPN has dropped the way I'm doing this having the user type in there IP before they start the VPN and then they start the VPN and it checks to see if it changes. My problem is that when I compare the two strings even if they are the same the program stays they are different.

Imports System.Net
Imports System.IO

Public Class Form1

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        LbIP.Text = GetIP()
    End Sub

    Function GetIP() As String
        Dim IP As New WebClient
        Return IP.DownloadString("http://icanhazip.com/")
    End Function

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        If GetIP() = TextBox1.Text Then
            Label1.Text = "VPN DROPPED"
        Else
            Label1.Text = "Your Good"
        End If
    End Sub
End Class
Was it helpful?

Solution

DownloadString will return ip address with \n at the end of the string. you need to remove that and compare.

sample work around

  If GetIP().Replace("\n","") = TextBox1.Text Then
            Label1.Text = "VPN DROPPED"
        Else
            Label1.Text = "Your Good"
 End If
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top