منتدى فيجوال بيسك لكل العرب | منتدى المبرمجين العرب

نسخة كاملة : طلب كود خاص في Lan او Ethrnet
أنت حالياً تتصفح نسخة خفيفة من المنتدى . مشاهدة نسخة كاملة مع جميع الأشكال الجمالية .
السلام عليكم ورحمة الله 
طلبي هو كود تحقق مو وجود كيبل LAN مدرج في الابتوب 
صورة البورت الخاص بالـ LAN

يعني كود تحقق من وجود كبل شابك مع الابتوب او عدم وجود كيبل 

فقط هذا
كود :
Imports System.Net.NetworkInformation

Public Class Form1

   Dim networkInterfaces() As NetworkInterface
   Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
       networkInterfaces = NetworkInterface.GetAllNetworkInterfaces()

       If IsEthernetAvailable() Then
           MessageBox.Show("الكابل متصل" + Environment.NewLine + "اسم الشبكة : " + GetEthernetNetworkName() + Environment.NewLine + "الآي بي : " + GetIP())
       Else
           MessageBox.Show("كابل الشبكة غير متصل!")
       End If
   End Sub

   Function GetEthernetNetworkName() As String
       For Each networkInterface In networkInterfaces
           If networkInterface.NetworkInterfaceType = NetworkInterfaceType.Ethernet Then
               Return networkInterface.Name
           End If
       Next networkInterface
       Return Nothing
   End Function

   ''' Source https://stackoverflow.com/questions/27843591/how-to-distinguish-between-ethernet-and-wifi-ip-addresses-using-vb-net
   Function GetIP() As String
       Dim networkInterfaces() As NetworkInterface
       networkInterfaces = NetworkInterface.GetAllNetworkInterfaces()

       For Each networkInterface In networkInterfaces
           If networkInterface.NetworkInterfaceType = NetworkInterfaceType.Ethernet Then
               For Each address In networkInterface.GetIPProperties().UnicastAddresses
                   If address.Address.AddressFamily = Net.Sockets.AddressFamily.InterNetwork Then
                       Return address.Address.ToString()
                   End If
               Next address
           End If
       Next networkInterface

       Return Nothing
   End Function

   Public Function IsEthernetAvailable() As Boolean
       ''' Source : https://social.msdn.microsoft.com/Forums/vstudio/en-US/8c21fff7-adb5-47b2-bdde-c9196b19ca0e/ethernet-cable-check?forum=vbgeneral
       Dim result As Boolean = False
       For Each adapter As System.Net.NetworkInformation.NetworkInterface In System.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces
           'adapter type should be one of Ethernet
           If adapter.NetworkInterfaceType = Net.NetworkInformation.NetworkInterfaceType.Ethernet OrElse
               adapter.NetworkInterfaceType = Net.NetworkInformation.NetworkInterfaceType.Ethernet3Megabit OrElse
               adapter.NetworkInterfaceType = Net.NetworkInformation.NetworkInterfaceType.FastEthernetFx OrElse
               adapter.NetworkInterfaceType = Net.NetworkInformation.NetworkInterfaceType.FastEthernetT OrElse
               adapter.NetworkInterfaceType = Net.NetworkInformation.NetworkInterfaceType.GigabitEthernet Then
               'physical adapter will not have a zero value for first byte of MAC address
               If adapter.GetPhysicalAddress.GetAddressBytes(0) <> 0 Then
                   If adapter.OperationalStatus = Net.NetworkInformation.OperationalStatus.Up Then
                       result = True
                       Exit For
                   End If
               End If
           End If
       Next
       Return result
   End Function

End Class
(06-08-19, 04:28 AM)محمد كريّم كتب : [ -> ]
كود :
Imports System.Net.NetworkInformation

Public Class Form1

   Dim networkInterfaces() As NetworkInterface
   Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
       networkInterfaces = NetworkInterface.GetAllNetworkInterfaces()

       If IsEthernetAvailable() Then
           MessageBox.Show("الكابل متصل" + Environment.NewLine + "اسم الشبكة : " + GetEthernetNetworkName() + Environment.NewLine + "الآي بي : " + GetIP())
       Else
           MessageBox.Show("كابل الشبكة غير متصل!")
       End If
   End Sub

   Function GetEthernetNetworkName() As String
       For Each networkInterface In networkInterfaces
           If networkInterface.NetworkInterfaceType = NetworkInterfaceType.Ethernet Then
               Return networkInterface.Name
           End If
       Next networkInterface
       Return Nothing
   End Function

   ''' Source https://stackoverflow.com/questions/27843591/how-to-distinguish-between-ethernet-and-wifi-ip-addresses-using-vb-net
   Function GetIP() As String
       Dim networkInterfaces() As NetworkInterface
       networkInterfaces = NetworkInterface.GetAllNetworkInterfaces()

       For Each networkInterface In networkInterfaces
           If networkInterface.NetworkInterfaceType = NetworkInterfaceType.Ethernet Then
               For Each address In networkInterface.GetIPProperties().UnicastAddresses
                   If address.Address.AddressFamily = Net.Sockets.AddressFamily.InterNetwork Then
                       Return address.Address.ToString()
                   End If
               Next address
           End If
       Next networkInterface

       Return Nothing
   End Function

   Public Function IsEthernetAvailable() As Boolean
       ''' Source : https://social.msdn.microsoft.com/Forums/vstudio/en-US/8c21fff7-adb5-47b2-bdde-c9196b19ca0e/ethernet-cable-check?forum=vbgeneral
       Dim result As Boolean = False
       For Each adapter As System.Net.NetworkInformation.NetworkInterface In System.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces
           'adapter type should be one of Ethernet
           If adapter.NetworkInterfaceType = Net.NetworkInformation.NetworkInterfaceType.Ethernet OrElse
               adapter.NetworkInterfaceType = Net.NetworkInformation.NetworkInterfaceType.Ethernet3Megabit OrElse
               adapter.NetworkInterfaceType = Net.NetworkInformation.NetworkInterfaceType.FastEthernetFx OrElse
               adapter.NetworkInterfaceType = Net.NetworkInformation.NetworkInterfaceType.FastEthernetT OrElse
               adapter.NetworkInterfaceType = Net.NetworkInformation.NetworkInterfaceType.GigabitEthernet Then
               'physical adapter will not have a zero value for first byte of MAC address
               If adapter.GetPhysicalAddress.GetAddressBytes(0) <> 0 Then
                   If adapter.OperationalStatus = Net.NetworkInformation.OperationalStatus.Up Then
                       result = True
                       Exit For
                   End If
               End If
           End If
       Next
       Return result
   End Function

End Class

بارك الله بيك هو هذا المطلوب