26-05-18, 10:08 AM
(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
و يمكن ايضا معالجة نفس الكود عبر مكتبة ManagementPHP كود :
Dim macs As List(Of String) = GetMacs()
For Each str As String In macs
TextBox1.AppendText(str + vbNewLine)
Next
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
الفحص سيبدأ من هذا الرقم 192.168.1 و وصولاً الى هذا الرقم 192.168.255PHP كود :
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
بالتوفيق
جزاك الله خيرا يا ابوليلى
لا يلومني على انقطاعاتي المتكررة
فهي اما عمل او دراسة او تربية
سُبْحَانَكَ اللَّهُمَّ وَبِحَمْدِكَ، أَشُهَّدٌ أَنَّ لَا إلَهَ إلا أَنْتَ، أَسَتَغْفِرُكَ وَأَتُوبَ إِلَيْكَ
فهي اما عمل او دراسة او تربية
سُبْحَانَكَ اللَّهُمَّ وَبِحَمْدِكَ، أَشُهَّدٌ أَنَّ لَا إلَهَ إلا أَنْتَ، أَسَتَغْفِرُكَ وَأَتُوبَ إِلَيْكَ
