12-08-19, 03:58 PM
السلام عليكم ورحمة الله
عيدكم مبارك ان شاء الله
ممكن حل لهذا الكود .
كود :
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim arr As Array = VPN()
If arr.GetValue(0) = True Then
MsgBox(String.Format("
name: {0}
address: {1}
description: {2}", arr.GetValue(1), arr.GetValue(2), arr.GetValue(3)))
Else
MsgBox("لايوجد اتصال")
End If
End Subما هو الحل
هذه صورة الخطأ
وهذا الكود كامل
كود :
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim arr As Array = VPN()
If arr.GetValue(0) = True Then
MsgBox(String.Format("
name: {0}
address: {1}
description: {2}", arr.GetValue(1), arr.GetValue(2), arr.GetValue(3)))
Else
MsgBox("لايوجد اتصال")
End If
End Sub
Private Function VPN() As Array
Dim nic As Net.NetworkInformation.NetworkInterface() = Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces
If Not nic.Length < 0 And nic IsNot Nothing Then
For Each netadapter As Net.NetworkInformation.NetworkInterface In nic
'MsgBox(netadapter.Name)
If netadapter.Name.ToLower.Trim.Contains("vpn") Then ' Or netadapter.Name.Equals("openVPN") ?
If netadapter.OperationalStatus = Net.NetworkInformation.OperationalStatus.Up Then
For Each addr In netadapter.GetIPProperties().UnicastAddresses
If addr.Address.AddressFamily = Net.Sockets.AddressFamily.InterNetwork Then
Return {True, netadapter.Name, addr.Address.ToString, netadapter.Description}
End If
Next
End If
End If
Next
End If
Return {False, Nothing, Nothing, Nothing}
End Function
End Class