如何检测实时IP更改?
示例:
我的没有VPN的ip:3.3.3.3,每当我连接到vpn时,我的ip变为5.5.5.5。 我的问题是:如何在表单运行时检测到IP已更改?
我试过了:
Private Sub Timer4_Tick(sender As Object, e As EventArgs) Handles Timer4.Tick
Dim adapters As NetworkInterface() = NetworkInterface.GetAllNetworkInterfaces()
AddHandler NetworkChange.NetworkAddressChanged, AddressOf downloadip
Dim n As NetworkInterface
For Each n In adapters
Timer4.Stop()
Msgbox("IP Changed")
Next n
End Sub
答案 0 :(得分:0)
尝试在外部网站上查看您的IP
例如:
Public Sub GetExternalIp()
Try
Dim WithEvents IPBrowser As New WebBrowser
IPBrowser.Visible = False
Me.Controls.Add(IPBrowser)
IpBrowser.Navigate("http://seemyip.com/onyoursite.php")
Catch
Label2.Text = "failed to get external IP"
End Try
End Sub
'then, put this OnNavigatingEvent
If IpBrowser.Document.All("ip").GetAttribute("value") IsNot Nothing Then
MyExtIp = IpBrowser.Document.All("ip").GetAttribute("value")
Else
MessageBox.Show("Can't find your IP")
End If