tags:

views:

163

answers:

0

Actually i want MAC address of the remote server so i am using SendARP method. But problem is that it is returning "" or "00-00-00-00-00-00". Actually in my network some PC's having two IP addresses.I think server also having the two IPs. For some PC in the same network my program works fine, only for 2-3 machine its giving this kind of problem. Code for the same is as follow:

<DllImport("iphlpapi.dll", ExactSpelling:=True)> _
    Public Shared Function SendARP(ByVal DestIP As Integer, ByVal SrcIP As Integer, <Out()> ByVal pMacAddr As Byte(), ByRef PhyAddrLen As Integer) As Integer
    End Function
Public Function GetMacAddress(ByVal sName As String) As String
        Try
            Dim s As String = String.Empty
            Dim Tempaddr As IPHostEntry = Nothing
            Tempaddr = DirectCast(Dns.GetHostEntry(sName), System.Net.IPHostEntry)
            Dim TempAd As System.Net.IPAddress() = Tempaddr.AddressList
            Dim Ipaddr As String() = New String(3) {}
            For Each TempA As IPAddress In TempAd
                Ipaddr(1) = TempA.ToString()
                Dim ab As Byte() = New Byte(6) {}
                Dim len As Integer = ab.Length
                Dim r As Integer = SendARP(CInt(TempA.Address), 0, ab, len)
                Dim sMAC As String = BitConverter.ToString(ab, 0, 6)
                Ipaddr(2) = sMAC
                s = sMAC
            Next
            Return s.ToUpper
        Catch ex As Exception
            Return ""
        End Try
    End Function

Can anybody please help me...