استخراج Mac Adrress + استخراج الاجهزة على الشبكة - ابو ليلى - 14-07-17
مجموعة تجارب اخر الليل
كود لاستخراج Mac Adrress الخاص ببطاقات الشبكة على الجهاز مع تنسيقه بالشكل المطلوب
اعمل مشروع جديد و ضيف مربع نص و زر و ProgressBar
استورد فضاء الاسماء System.Net.NetworkInformation
الاجراء الاول تفصيلي
PHP كود :
Public Sub ShowNetworkInterfaces() Dim computerProperties As IPGlobalProperties = IPGlobalProperties.GetIPGlobalProperties() Dim nics As NetworkInterface() = NetworkInterface.GetAllNetworkInterfaces() TextBox1.AppendText(String.Format("Interface information for {0}.{1}.{2} ", computerProperties.HostName, computerProperties.DomainName, computerProperties.GetIcmpV4Statistics) + vbNewLine) If nics Is Nothing OrElse nics.Length < 1 Then TextBox1.AppendText(" No network interfaces found." + vbNewLine) Return End If
TextBox1.AppendText(String.Format(" Number of interfaces .................... : {0}", nics.Length) + vbNewLine) For Each adapter As NetworkInterface In nics
Dim properties As IPInterfaceProperties = adapter.GetIPProperties() Dim p As IPv4InterfaceProperties = properties.GetIPv4Properties()
TextBox1.AppendText([String].Empty.PadLeft(adapter.Description.Length, "="c) + vbNewLine) TextBox1.AppendText(adapter.Description + vbNewLine) TextBox1.AppendText(String.Format(" Interface type .......................... : {0}", adapter.NetworkInterfaceType) + vbNewLine) TextBox1.AppendText(" Physical address ........................ : " + vbNewLine) Dim address As PhysicalAddress = adapter.GetPhysicalAddress() Dim bytes As Byte() = address.GetAddressBytes() Dim Mac As String = "" For i As Integer = 0 To bytes.Length - 1
' Display the physical address in hexadecimal. Mac += (String.Format("{0}", bytes(i).ToString("X2")))
If i <> bytes.Length - 1 Then Mac += (("-")) End If Next TextBox1.AppendText(Mac + vbNewLine) TextBox1.AppendText(adapter.OperationalStatus.ToString + vbNewLine)
TextBox1.AppendText(String.Format(" Index ............................. : {0}", p.Index) + vbNewLine) TextBox1.AppendText(String.Format(" MTU ............................... : {0}", p.Mtu) + vbNewLine) TextBox1.AppendText(String.Format(" APIPA active....................... : {0}", p.IsAutomaticPrivateAddressingActive) + vbNewLine) TextBox1.AppendText(String.Format(" APIPA enabled...................... : {0}", p.IsAutomaticPrivateAddressingEnabled) + vbNewLine) TextBox1.AppendText(String.Format(" Forwarding enabled................. : {0}", p.IsForwardingEnabled) + vbNewLine) TextBox1.AppendText(String.Format(" Uses WINS ......................... : {0}", p.UsesWins) + vbNewLine)
Next
End Sub
و يمكنك اختصاره للحصول على العنواين فقط بدون التفاصيل
PHP كود :
Public Function GetMacs() As List(Of String) Dim Macs As New List(Of String) Dim Ntcs As NetworkInterface() = NetworkInterface.GetAllNetworkInterfaces() For Each adapter As NetworkInterface In Ntcs Dim address As PhysicalAddress = adapter.GetPhysicalAddress() Dim bytes As Byte() = address.GetAddressBytes() Dim Mac As String = "" For i As Integer = 0 To bytes.Length - 1 Mac += bytes(i).ToString("X2") If i <> bytes.Length - 1 Then Mac += "-" End If Next Macs.Add(Mac) Next Return Macs End Function
و الاستدعاء
PHP كود :
Dim macs As List(Of String) = GetMacs() For Each str As String In macs TextBox1.AppendText(str + vbNewLine) Next
و يمكن ايضا معالجة نفس الكود عبر مكتبة Management
PHP كود :
Private Sub GetMacs2() Dim pc As String = Environment.MachineName Dim theScope As New ManagementScope("root\CIMV2") Dim theQueryBuilder As New SelectQuery("Win32_NetworkAdapter") Dim theSearcher As New ManagementObjectSearcher(theScope, theQueryBuilder)
For Each mac As ManagementObject In theSearcher.Get If Not IsNothing(mac("MACAddress")) Then TextBox1.AppendText(mac("MACAddress").ToString + vbNewLine)
End If
Next
End Sub
الكود الثاني لفحص الاجهزة الموجودة على الشبكة مع جلب الاسم و الـ ip الخاص بالجهاز
نعرف متغيرين اعلى الفورم
PHP كود :
Shared countdown As CountdownEvent Shared upCount As Integer = 0
و من ثم اجراء الفحص
PHP كود :
Private Sub CheckIps() countdown = New CountdownEvent(1) Dim sw As New Stopwatch() sw.Start() Dim ipBase As String = "192.168.1." ProgressBar1.Maximum = 254 TextBox1.Clear()
For i As Integer = 1 To 254 Dim ip As String = ipBase & i.ToString()
Dim p As New Ping() Dim options As PingOptions = New PingOptions()
options.DontFragment = True AddHandler p.PingCompleted, New PingCompletedEventHandler(AddressOf CompletedPings) countdown.AddCount() p.SendAsync(ip, 100, ip) ProgressBar1.Value = i Next
countdown.Signal() countdown.Wait(100) sw.[Stop]() Dim span As New TimeSpan(sw.ElapsedTicks) TextBox1.AppendText(String.Format("Took {0} milliseconds. {1} hosts active.", sw.ElapsedMilliseconds, upCount) + Environment.NewLine) End Sub
PHP كود :
Private Sub CompletedPings(sender As Object, e As PingCompletedEventArgs) Dim ip As String = DirectCast(e.UserState, String) If e.Reply IsNot Nothing AndAlso e.Reply.Status = IPStatus.Success Then Dim name As String Try Dim hostEntry As IPHostEntry = Dns.GetHostEntry(ip) name = hostEntry.HostName Catch ex As SocketException name = "?" End Try TextBox1.AppendText(String.Format("{0} ({1}) is up: ({2} ms)", ip, name, e.Reply.RoundtripTime) + Environment.NewLine) ElseIf e.Reply Is Nothing OrElse e.Reply.Status = IPStatus.TimedOut Then TextBox1.AppendText(String.Format("Pinging {0} failed. (No Response ? )", ip) + Environment.NewLine) End If countdown.Signal() End Sub
الفحص سيبدأ من هذا الرقم 192.168.1 و وصولاً الى هذا الرقم 192.168.255
بالتوفيق
RE: استخراج Mac Adrress + استخراج الاجهزة على الشبكة - sendbad100 - 14-07-17
السلام عليكم ورحمة الله وبركاته
جزاك الله الف خير
الله يعطيك الف عافية
RE: استخراج Mac Adrress + استخراج الاجهزة على الشبكة - الوايلي - 10-05-18
يعطيك العافية ابو ليلى
بس عندي سؤال الكود الأخير
الفحص سيبدأ من هذا الرقم 192.168.1 و وصولاً الى هذا الرقم 192.168.255
باي حدث اضعه
RE: استخراج Mac Adrress + استخراج الاجهزة على الشبكة - ابو ليلى - 10-05-18
(10-05-18, 01:41 AM)الوايلي كتب : يعطيك العافية ابو ليلى
بس عندي سؤال الكود الأخير
الفحص سيبدأ من هذا الرقم 192.168.1 و وصولاً الى هذا الرقم 192.168.255
باي حدث اضعه
سؤال محرج فعلاً ,
الموضوع كتبته مرة في مكان كان به شبكة و خطر ببالي التجريب .
من دراسة الكود ضع المتغيرات و الاجراءات في الفورم و من ثم في حدث اي زر قم باستدعاء الاجراء CheckIps
و ان شاء الله يعمل.
RE: استخراج Mac Adrress + استخراج الاجهزة على الشبكة - الوايلي - 10-05-18
آسف لو سببت احراجات لك
الله يجزاك خير يتم التجربة الآن ومشكور على وقتك استاذ ابو ليلى
RE: استخراج Mac Adrress + استخراج الاجهزة على الشبكة - ahmed.m - 21-05-18
بوركت اخي الكريم
RE: استخراج Mac Adrress + استخراج الاجهزة على الشبكة - ابو ابراهيم - 26-05-18
(14-07-17, 04:40 AM)ابو ليلى كتب : مجموعة تجارب اخر الليل
كود لاستخراج Mac Adrress الخاص ببطاقات الشبكة على الجهاز مع تنسيقه بالشكل المطلوب
اعمل مشروع جديد و ضيف مربع نص و زر و ProgressBar
استورد فضاء الاسماء System.Net.NetworkInformation
الاجراء الاول تفصيلي
PHP كود :
Public Sub ShowNetworkInterfaces() Dim computerProperties As IPGlobalProperties = IPGlobalProperties.GetIPGlobalProperties() Dim nics As NetworkInterface() = NetworkInterface.GetAllNetworkInterfaces() TextBox1.AppendText(String.Format("Interface information for {0}.{1}.{2} ", computerProperties.HostName, computerProperties.DomainName, computerProperties.GetIcmpV4Statistics) + vbNewLine) If nics Is Nothing OrElse nics.Length < 1 Then TextBox1.AppendText(" No network interfaces found." + vbNewLine) Return End If
TextBox1.AppendText(String.Format(" Number of interfaces .................... : {0}", nics.Length) + vbNewLine) For Each adapter As NetworkInterface In nics
Dim properties As IPInterfaceProperties = adapter.GetIPProperties() Dim p As IPv4InterfaceProperties = properties.GetIPv4Properties()
TextBox1.AppendText([String].Empty.PadLeft(adapter.Description.Length, "="c) + vbNewLine) TextBox1.AppendText(adapter.Description + vbNewLine) TextBox1.AppendText(String.Format(" Interface type .......................... : {0}", adapter.NetworkInterfaceType) + vbNewLine) TextBox1.AppendText(" Physical address ........................ : " + vbNewLine) Dim address As PhysicalAddress = adapter.GetPhysicalAddress() Dim bytes As Byte() = address.GetAddressBytes() Dim Mac As String = "" For i As Integer = 0 To bytes.Length - 1
' Display the physical address in hexadecimal. Mac += (String.Format("{0}", bytes(i).ToString("X2")))
If i <> bytes.Length - 1 Then Mac += (("-")) End If Next TextBox1.AppendText(Mac + vbNewLine) TextBox1.AppendText(adapter.OperationalStatus.ToString + vbNewLine)
TextBox1.AppendText(String.Format(" Index ............................. : {0}", p.Index) + vbNewLine) TextBox1.AppendText(String.Format(" MTU ............................... : {0}", p.Mtu) + vbNewLine) TextBox1.AppendText(String.Format(" APIPA active....................... : {0}", p.IsAutomaticPrivateAddressingActive) + vbNewLine) TextBox1.AppendText(String.Format(" APIPA enabled...................... : {0}", p.IsAutomaticPrivateAddressingEnabled) + vbNewLine) TextBox1.AppendText(String.Format(" Forwarding enabled................. : {0}", p.IsForwardingEnabled) + vbNewLine) TextBox1.AppendText(String.Format(" Uses WINS ......................... : {0}", p.UsesWins) + vbNewLine)
Next
End Sub
و يمكنك اختصاره للحصول على العنواين فقط بدون التفاصيل
PHP كود :
Public Function GetMacs() As List(Of String) Dim Macs As New List(Of String) Dim Ntcs As NetworkInterface() = NetworkInterface.GetAllNetworkInterfaces() For Each adapter As NetworkInterface In Ntcs Dim address As PhysicalAddress = adapter.GetPhysicalAddress() Dim bytes As Byte() = address.GetAddressBytes() Dim Mac As String = "" For i As Integer = 0 To bytes.Length - 1 Mac += bytes(i).ToString("X2") If i <> bytes.Length - 1 Then Mac += "-" End If Next Macs.Add(Mac) Next Return Macs End Function
و الاستدعاء
PHP كود :
Dim macs As List(Of String) = GetMacs() For Each str As String In macs TextBox1.AppendText(str + vbNewLine) Next
و يمكن ايضا معالجة نفس الكود عبر مكتبة Management
PHP كود :
Private Sub GetMacs2() Dim pc As String = Environment.MachineName Dim theScope As New ManagementScope("root\CIMV2") Dim theQueryBuilder As New SelectQuery("Win32_NetworkAdapter") Dim theSearcher As New ManagementObjectSearcher(theScope, theQueryBuilder)
For Each mac As ManagementObject In theSearcher.Get If Not IsNothing(mac("MACAddress")) Then TextBox1.AppendText(mac("MACAddress").ToString + vbNewLine)
End If
Next
End Sub
الكود الثاني لفحص الاجهزة الموجودة على الشبكة مع جلب الاسم و الـ ip الخاص بالجهاز
نعرف متغيرين اعلى الفورم
PHP كود :
Shared countdown As CountdownEvent Shared upCount As Integer = 0
و من ثم اجراء الفحص
PHP كود :
Private Sub CheckIps() countdown = New CountdownEvent(1) Dim sw As New Stopwatch() sw.Start() Dim ipBase As String = "192.168.1." ProgressBar1.Maximum = 254 TextBox1.Clear()
For i As Integer = 1 To 254 Dim ip As String = ipBase & i.ToString()
Dim p As New Ping() Dim options As PingOptions = New PingOptions()
options.DontFragment = True AddHandler p.PingCompleted, New PingCompletedEventHandler(AddressOf CompletedPings) countdown.AddCount() p.SendAsync(ip, 100, ip) ProgressBar1.Value = i Next
countdown.Signal() countdown.Wait(100) sw.[Stop]() Dim span As New TimeSpan(sw.ElapsedTicks) TextBox1.AppendText(String.Format("Took {0} milliseconds. {1} hosts active.", sw.ElapsedMilliseconds, upCount) + Environment.NewLine) End Sub
PHP كود :
Private Sub CompletedPings(sender As Object, e As PingCompletedEventArgs) Dim ip As String = DirectCast(e.UserState, String) If e.Reply IsNot Nothing AndAlso e.Reply.Status = IPStatus.Success Then Dim name As String Try Dim hostEntry As IPHostEntry = Dns.GetHostEntry(ip) name = hostEntry.HostName Catch ex As SocketException name = "?" End Try TextBox1.AppendText(String.Format("{0} ({1}) is up: ({2} ms)", ip, name, e.Reply.RoundtripTime) + Environment.NewLine) ElseIf e.Reply Is Nothing OrElse e.Reply.Status = IPStatus.TimedOut Then TextBox1.AppendText(String.Format("Pinging {0} failed. (No Response ? )", ip) + Environment.NewLine) End If countdown.Signal() End Sub
الفحص سيبدأ من هذا الرقم 192.168.1 و وصولاً الى هذا الرقم 192.168.255
بالتوفيق
جزاك الله خيرا يا ابوليلى
RE: استخراج Mac Adrress + استخراج الاجهزة على الشبكة - thementalist - 08-09-18
هل يوجد تعديل علي الكود انه في حالة انفصال النت لانه في حالة انفصال النت يطلع لي رساله في مسج بوكس
RE: استخراج Mac Adrress + استخراج الاجهزة على الشبكة - viv - 21-09-18
الفحص سيبدأ من هذا الرقم 192.168.1 و وصولاً الى هذا الرقم 192.168.255
تعديل بسيط اعتقد
الفحص سيبدأ من هذا الرقم 192.168.1.1 و وصولاً الى هذا الرقم 192.168.1.255
RE: استخراج Mac Adrress + استخراج الاجهزة على الشبكة - معتز حسن - 15-10-19
مشكوووووووووووووور
|