Questo da IP
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Network_Probe()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
MsgBox("MAC Host = " & MACHost & vbCrLf & "MAC Address = " & MACAddress)
End Sub
End Class
Imports System.Net.NetworkInformation
Imports System.Diagnostics
Module Module1
Friend NetworkInterfaces() As NetworkInterface
Friend MACHost As String = "00:00:00:00:00:00"
Friend TestIP As String = "192.168.0.1"
Friend MACAddress As String = "00:00:00:00:00:00"
Friend Sub Network_Probe()
Try
NetworkInterfaces = NetworkInterface.GetAllNetworkInterfaces()
For Each ni In NetworkInterfaces
If ni.OperationalStatus = OperationalStatus.Up AndAlso ni.NetworkInterfaceType = NetworkInterfaceType.Ethernet Then
Dim MAC() As Byte = ni.GetPhysicalAddress().GetAddressBytes
If Not MAC Is Nothing AndAlso MAC.Length >= 6 Then
MACHost = Hex(MAC(0)).PadLeft(2, "0") & ":" & Hex(MAC(1)).PadLeft(2, "0") & ":" & Hex(MAC(2)).PadLeft(2, "0") & ":" _
& Hex(MAC(3)).PadLeft(2, "0") & ":" & Hex(MAC(4)).PadLeft(2, "0") & ":" & Hex(MAC(5)).PadLeft(2, "0")
Exit For
End If
End If
Next
Dim ping As Ping = New Ping()
AddHandler ping.PingCompleted, AddressOf Ping_completed
ping.SendAsync(TestIP, 500, TestIP)
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Private Sub Ping_completed(ByVal sender As Object, ByVal e As PingCompletedEventArgs)
If e.Reply IsNot Nothing AndAlso e.Reply.Status = IPStatus.Success AndAlso CStr(e.UserState) = TestIP Then
Dim proc As Process = New Process()
proc.StartInfo.FileName = "arp"
proc.StartInfo.Arguments = "-a " & TestIP
proc.StartInfo.UseShellExecute = False
proc.StartInfo.RedirectStandardOutput = True
proc.StartInfo.CreateNoWindow = True
proc.Start()
Dim s As String() = proc.StandardOutput.ReadToEnd().Split("-")
If Not s Is Nothing AndAlso s.Length >= 8 Then
MACAddress = s(3).Substring(Math.Max(0, s(3).Length - 2)).ToUpper & ":" & s(4).ToUpper & ":" & s(5).ToUpper _
& ":" & s(6).ToUpper & ":" & s(7).ToUpper & ":" + s(8).Substring(0, 2).ToUpper
End If
Else
MsgBox("No reply from IP " & TestIP)
End If
End Sub
End Module
Dal nome host lo ricavi dagli esempi precedenti