تقييم الموضوع :
  • 0 أصوات - بمعدل 0
  • 1
  • 2
  • 3
  • 4
  • 5
[كود] استخراج Mac Adrress + استخراج الاجهزة على الشبكة
#1
مجموعة تجارب اخر الليل
كود لاستخراج  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.HostNamecomputerProperties.DomainNamecomputerProperties.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(theScopetheQueryBuilder)

 
       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 
و من ثم اجراء الفحص
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(ip100ip)
 
           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.ElapsedMillisecondsupCount) + Environment.NewLine)
 
   End Sub 

PHP كود :
   Private Sub CompletedPings(sender As ObjectAs PingCompletedEventArgs)
 
       Dim ip As String DirectCast(e.UserStateString)
 
       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)"ipnamee.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

بالتوفيق
اللهم لك الحمد كما ينبغي لجلال وجهك و عظيم سلطانك
في حل و ترحال
الرد }}}
#2
السلام عليكم ورحمة الله وبركاته

جزاك الله الف خير

الله يعطيك الف عافية
الرد }}}
تم الشكر بواسطة: ابو ليلى
#3
يعطيك العافية ابو ليلى 

بس عندي سؤال الكود الأخير 


الفحص سيبدأ من هذا الرقم   192.168.1  و وصولاً الى  هذا الرقم   192.168.255
باي حدث اضعه 
الرد }}}
تم الشكر بواسطة: ابو ليلى
#4
(10-05-18, 01:41 AM)الوايلي كتب : يعطيك العافية ابو ليلى 

بس عندي سؤال الكود الأخير 


الفحص سيبدأ من هذا الرقم   192.168.1  و وصولاً الى  هذا الرقم   192.168.255
باي حدث اضعه 

سؤال محرج فعلاً ,  Big Grin

الموضوع كتبته مرة في مكان كان به شبكة و خطر ببالي التجريب .
من دراسة الكود ضع المتغيرات و الاجراءات في الفورم و من ثم في حدث اي زر قم باستدعاء الاجراء  CheckIps
و ان شاء الله يعمل.
اللهم لك الحمد كما ينبغي لجلال وجهك و عظيم سلطانك
في حل و ترحال
الرد }}}
تم الشكر بواسطة:
#5
آسف لو سببت احراجات لك 
الله يجزاك خير يتم التجربة الآن ومشكور على وقتك استاذ ابو ليلى 

الرد }}}
تم الشكر بواسطة: ابو ليلى
#6
بوركت اخي الكريم
الرد }}}
تم الشكر بواسطة: ابو ليلى
#7
(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.HostNamecomputerProperties.DomainNamecomputerProperties.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(theScopetheQueryBuilder)

 
       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 
و من ثم اجراء الفحص
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(ip100ip)
 
           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.ElapsedMillisecondsupCount) + Environment.NewLine)
 
   End Sub 

PHP كود :
   Private Sub CompletedPings(sender As ObjectAs PingCompletedEventArgs)
 
       Dim ip As String DirectCast(e.UserStateString)
 
       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)"ipnamee.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

بالتوفيق



جزاك الله خيرا يا ابوليلى
لا يلومني على انقطاعاتي المتكررة
فهي اما عمل او دراسة او تربية




سُبْحَانَكَ اللَّهُمَّ وَبِحَمْدِكَ، أَشُهَّدٌ أَنَّ لَا إلَهَ إلا أَنْتَ، أَسَتَغْفِرُكَ وَأَتُوبَ إِلَيْكَ
الرد }}}
تم الشكر بواسطة: ابو ليلى
#8
هل يوجد تعديل علي الكود انه في حالة انفصال النت لانه في حالة انفصال النت يطلع لي رساله في مسج بوكس
الرد }}}
تم الشكر بواسطة: ابو ليلى
#9
الفحص سيبدأ من هذا الرقم   192.168.1  و وصولاً الى  هذا الرقم   192.168.255
تعديل بسيط اعتقد
الفحص سيبدأ من هذا الرقم  192.168.1.1 و وصولاً الى  هذا الرقم   192.168.1.255
الرد }}}
#10
مشكوووووووووووووور
الرد }}}
تم الشكر بواسطة: elgokr , ابو ليلى


المواضيع المحتمل أن تكون متشابهة .
الموضوع : الكاتب الردود : المشاهدات : آخر رد
  [VB.NET] تشغيل قاعدة البيانات التي على السيرفر من اي جهاز على الشبكة ahmed saleh 4 6,153 10-03-19, 09:49 AM
آخر رد: معتز حسن
  [كود] بديل مؤقت لاكواد كشف الاجهزة المتصلة بالشبكة سعود 1 2,834 06-10-15, 10:00 PM
آخر رد: سعود

التنقل السريع :


يقوم بقرائة الموضوع: بالاضافة الى ( 1 ) ضيف كريم